-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix navigation bug on iOS * prepare 10.1.5 release * refactor common code functionality for embedding swiftui view for each of the job screens into a new function and reuse it in those screens. --------- Co-authored-by: Tobi Omotayo <tobitech@ymail.com>
- Loading branch information
Showing
9 changed files
with
58 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import Flutter | ||
import UIKit | ||
import SwiftUI | ||
|
||
extension FlutterPlatformView { | ||
/// Embeds a SwiftUI view into a UIKit view hierarchy for a view class that conforms to `FlutterPlatformView` | ||
/// - Parameters: | ||
/// - swiftUIView: The SwiftUI view to be integrated. This can be any view conforming | ||
/// to the `View` protocol. | ||
/// - parentView: The UIKit view that will contain the SwiftUI view. | ||
/// - frame: The frame to be used for the hosted SwiftUI view. | ||
/// - Returns: The `UIViewController` (specifically, a `UIHostingController`) that hosts | ||
/// the SwiftUI view. This can be used for further configuration or management. | ||
/// | ||
/// - Note: This function attempts to find the appropriate parent view controller to add | ||
/// the hosting controller as a child. It first checks for a `UINavigationController` | ||
/// with a `FlutterViewController`, which is common in Flutter-based apps with SwiftUI | ||
/// integration. If not found, it falls back to the root view controller. | ||
/// | ||
/// - Important: Ensure that you maintain a strong reference to the returned view controller | ||
/// to prevent it from being deallocated. | ||
func embedView<T: View>( | ||
_ swiftUIView: T, | ||
in parentView: UIView, | ||
frame: CGRect | ||
) -> UIViewController { | ||
let hostingController = UIHostingController(rootView: swiftUIView) | ||
|
||
hostingController.view.frame = frame | ||
hostingController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight] | ||
parentView.addSubview(hostingController.view) | ||
|
||
if let navigationController = UIApplication.shared.windows.first?.rootViewController as? UINavigationController, | ||
let flutterViewController = navigationController.viewControllers.first as? FlutterViewController { | ||
flutterViewController.addChild(hostingController) | ||
parentView.addSubview(hostingController.view) | ||
hostingController.view.setNeedsLayout() | ||
hostingController.view.layoutIfNeeded() | ||
} else { | ||
let rootViewController = UIApplication.shared.windows.first?.rootViewController | ||
rootViewController?.addChild(hostingController) | ||
} | ||
|
||
return hostingController | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters