Skip to content

Commit

Permalink
Updates example (#37)
Browse files Browse the repository at this point in the history
* Updates readme file

* Updates example

* Adds launch screen to sample app
  • Loading branch information
felilo authored Dec 14, 2024
1 parent e904440 commit 20cac01
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
D9107CFB2B6703D80039F40D /* NavigationActionListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9107CFA2B6703D80039F40D /* NavigationActionListView.swift */; };
D91AD1F42D0D0BDC00C0FEAA /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D91AD1F32D0D0BDC00C0FEAA /* LaunchScreen.storyboard */; };
D95389212B643BAD000E3357 /* SUICoordinatorExampleApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = D95389202B643BAD000E3357 /* SUICoordinatorExampleApp.swift */; };
D95389232B643BAD000E3357 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D95389222B643BAD000E3357 /* ContentView.swift */; };
D95389252B643BAE000E3357 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D95389242B643BAE000E3357 /* Assets.xcassets */; };
Expand Down Expand Up @@ -37,6 +38,8 @@

/* Begin PBXFileReference section */
D9107CFA2B6703D80039F40D /* NavigationActionListView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavigationActionListView.swift; sourceTree = "<group>"; };
D91AD1F32D0D0BDC00C0FEAA /* LaunchScreen.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = "<group>"; };
D91AD1F52D0D0E6200C0FEAA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
D953891D2B643BAD000E3357 /* SUICoordinatorExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SUICoordinatorExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
D95389202B643BAD000E3357 /* SUICoordinatorExampleApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SUICoordinatorExampleApp.swift; sourceTree = "<group>"; };
D95389222B643BAD000E3357 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -76,6 +79,14 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
D91AD1F12D0D0BAD00C0FEAA /* LaunchScreen */ = {
isa = PBXGroup;
children = (
D91AD1F32D0D0BDC00C0FEAA /* LaunchScreen.storyboard */,
);
path = LaunchScreen;
sourceTree = "<group>";
};
D95389142B643BAD000E3357 = {
isa = PBXGroup;
children = (
Expand All @@ -95,6 +106,8 @@
D953891F2B643BAD000E3357 /* SUICoordinatorExample */ = {
isa = PBXGroup;
children = (
D91AD1F52D0D0E6200C0FEAA /* Info.plist */,
D91AD1F12D0D0BAD00C0FEAA /* LaunchScreen */,
D9B455CE2B643FBD004DD03A /* App */,
D9B455EC2B643FBD004DD03A /* Coordinators */,
D9B455D12B643FBD004DD03A /* Modules */,
Expand Down Expand Up @@ -332,6 +345,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
D91AD1F42D0D0BDC00C0FEAA /* LaunchScreen.storyboard in Resources */,
D95389282B643BAE000E3357 /* Preview Assets.xcassets in Resources */,
D95389252B643BAE000E3357 /* Assets.xcassets in Resources */,
);
Expand Down Expand Up @@ -505,9 +519,10 @@
DEVELOPMENT_TEAM = "";
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = SUICoordinatorExample/Info.plist;
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
Expand Down Expand Up @@ -541,9 +556,10 @@
DEVELOPMENT_TEAM = "";
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = SUICoordinatorExample/Info.plist;
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
Expand All @@ -555,6 +571,7 @@
PRODUCT_BUNDLE_IDENTIFIER = afl.SUICoordinatorExample;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
"PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = "Developer Wildcard";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
SUPPORTS_MACCATALYST = NO;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ class AppDelegate: NSObject, UIApplicationDelegate {
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil
) -> Bool {
mainCoodinator = HomeCoordinator()

// Simulate the receipt of a notification or external trigger to present the some coordinator
DispatchQueue.main.asyncAfter(deadline: .now() + 10) {
Task { [weak self] in
// Create and present the CustomTabbarCoordinator in a sheet presentation style
let coordinator = CustomTabbarCoordinator()
try? await coordinator.forcePresentation(
presentationStyle: .sheet,
mainCoordinator: self?.mainCoodinator
)
}
}

return true
}
}
14 changes: 14 additions & 0 deletions Examples/SUICoordinatorExample/SUICoordinatorExample/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>UILaunchScreen</key>
<dict>
<key>UILaunchScreen</key>
<dict>
<key>New item</key>
<string></string>
</dict>
</dict>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="23504" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<device id="retina6_12" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="23506"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="EHf-IW-A2E">
<objects>
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="393" height="852"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" textAlignment="center" lineBreakMode="middleTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="GJd-Yh-RWb">
<rect key="frame" x="67" y="264" width="259.33333333333331" height="86"/>
<string key="text">SUICoordinator
Example</string>
<fontDescription key="fontDescription" type="boldSystem" pointSize="36"/>
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<viewLayoutGuide key="safeArea" id="Bcu-3y-fUS"/>
<color key="backgroundColor" systemColor="tertiaryLabelColor"/>
<constraints>
<constraint firstItem="GJd-Yh-RWb" firstAttribute="centerY" secondItem="Bcu-3y-fUS" secondAttribute="centerY" multiplier="0.7" id="7u7-l4-x2i"/>
<constraint firstItem="GJd-Yh-RWb" firstAttribute="centerX" secondItem="Bcu-3y-fUS" secondAttribute="centerX" id="8ei-xe-FxX"/>
</constraints>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="53" y="375"/>
</scene>
</scenes>
<resources>
<systemColor name="tertiaryLabelColor">
<color red="0.23529411759999999" green="0.23529411759999999" blue="0.26274509800000001" alpha="0.29803921570000003" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
</resources>
</document>
86 changes: 25 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,20 @@ enum HomeRoute: RouteType {
return .push
}
}


@ViewBuilder
var view: Body {
switch self {
case .push(let viewModel):
return PushView(viewModel: viewModel)
PushView(viewModel: viewModel)
case .sheet(let viewModel):
return SheetView(viewModel: viewModel)
SheetView(viewModel: viewModel)
case .fullscreen(let viewModel):
return FullscreenView(viewModel: viewModel)
FullscreenView(viewModel: viewModel)
case .detents(let viewModel):
return DetentsView(viewModel: viewModel)
DetentsView(viewModel: viewModel)
case .actionListView(let viewModel):
return NavigationActionListView(viewModel: viewModel)
NavigationActionListView(viewModel: viewModel)
}
}
}
Expand Down Expand Up @@ -90,8 +91,8 @@ class HomeCoordinator: Coordinator<HomeRoute> {
}

func presentTabbarCoordinator() async {
let coordinator = TabbarFlowCoordinator()
await navigate(to: coordinator, presentationStyle: .sheet)
let coordinator = CustomTabbarCoordinator()
await navigate(to: coordinator, presentationStyle: .sheet, animated: animated)
}

func close() async {
Expand Down Expand Up @@ -178,54 +179,6 @@ struct NavigationActionListView: View {
}
}
```

_____

### 3. Create MainCoordinator and its Routes

```swift
import SUICoordinator

class MainCoordinator: Coordinator<MainRoute> {

override init() {
super.init()
Task {
await startFlow(route: .splash, animated: false)
}
}

override func start(animated: Bool = true) async {
let coordinator = HomeCoordinator()
await navigate(to: coordinator, presentationStyle: .fullScreenCover, animated: animated)
}
}
```

```swift
import SUICoordinator
import SwiftUI

enum MainRoute: RouteType {

case splash

public var presentationStyle: TransitionPresentationStyle {
switch self {
case .splash:
return .push
}
}

@ViewBuilder
public var view: any View {
switch self {
case .splash:
SplashView()
}
}
}
```
_____

### Setup project
Expand All @@ -240,13 +193,26 @@ import SUICoordinator

class AppDelegate: NSObject, UIApplicationDelegate {

var mainCoodinator: (any CoordinatorType)?
var mainCoodinator: HomeCoordinator?

func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil
) -> Bool {
mainCoodinator = MainCoordinator()
mainCoodinator = HomeCoordinator()

// Simulate the receipt of a notification or external trigger to present some coordinator
DispatchQueue.main.asyncAfter(deadline: .now() + 10) {
Task { [weak self] in
// Create and present the CustomTabbarCoordinator in a sheet presentation style
let coordinator = CustomTabbarCoordinator()
try? await coordinator.forcePresentation(
presentationStyle: .fullScreenCover,
mainCoordinator: self?.mainCoodinator
)
}
}

return true
}
}
Expand All @@ -266,9 +232,7 @@ struct SUICoordinatorDemoApp: App {

var body: some Scene {
WindowGroup {
if let view = appDelegate.mainCoodinator?.view {
AnyView(view)
}
appDelegate.mainCoodinator?.getView()
}
}
}
Expand Down
17 changes: 0 additions & 17 deletions Sources/SUICoordinator/Coordinator/Coordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,4 @@ open class Coordinator<Route: RouteType>: ObservableObject, CoordinatorType {
open func start(animated: Bool = true) async {
fatalError("This method must be overwritten")
}

/// Forces the presentation of the coordinator.
///
/// - Parameters:
/// - animated: A boolean value indicating whether to animate the presentation.
/// - presentationStyle: The transition presentation style for the forced presentation.
/// - mainCoordinator: The main coordinator associated with the forced presentation.
/// - Throws: An error if the presentation cannot be forced.
/// SeeAlso: TransitionPresentationStyle
open func forcePresentation(
animated: Bool = true,
presentationStyle: TransitionPresentationStyle = .sheet,
mainCoordinator: (any CoordinatorType)? = nil
) async throws {
let topCoordinator = try mainCoordinator?.topCoordinator()
await topCoordinator?.navigate(to: self, presentationStyle: presentationStyle)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,21 @@ public extension CoordinatorType {
@MainActor func startFlow(route: Route, transitionStyle: TransitionPresentationStyle? = nil, animated: Bool = true) async -> Void {
router.mainView = route
}

/// Forces the presentation of the coordinator.
///
/// - Parameters:
/// - animated: A boolean value indicating whether to animate the presentation.
/// - presentationStyle: The transition presentation style for the forced presentation.
/// - mainCoordinator: The main coordinator associated with the forced presentation.
/// - Throws: An error if the presentation cannot be forced.
/// SeeAlso: TransitionPresentationStyle
public func forcePresentation(
animated: Bool = true,
presentationStyle: TransitionPresentationStyle = .sheet,
mainCoordinator: (any CoordinatorType)? = nil
) async throws {
let topCoordinator = try mainCoordinator?.topCoordinator()
await topCoordinator?.navigate(to: self, presentationStyle: presentationStyle)
}
}

0 comments on commit 20cac01

Please sign in to comment.