Skip to content

Fix navigation bug on iOS #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Notes

## 10.1.5

* Fix navigation issue on iOS Flutter app

## 10.1.4

* Bump iOS to 10.2.2 (https://github.com/smileidentity/ios/releases/tag/v10.2.2) which fixes retry crash)
Expand Down
4 changes: 2 additions & 2 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/smile_id/ios"

SPEC CHECKSUMS:
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
integration_test: 13825b8a9334a850581300559b8839134b124670
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
integration_test: ce0a3ffa1de96d1a89ca0ac26fca7ea18a749ef4
lottie-ios: fcb5e73e17ba4c983140b7d21095c834b3087418
smile_id: 6d62c54b3fcf0e2fb685c33b28c868477244ac54
SmileID: 9d95463475f933422b2ce136474813b528dbedb7
Expand Down
46 changes: 46 additions & 0 deletions ios/Classes/FlutterPlatformView+EmbedSwiftUIView.swift
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
}
}
9 changes: 1 addition & 8 deletions ios/Classes/SmileIDBiometricKYC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,7 @@ class SmileIDBiometricKYC : NSObject, FlutterPlatformView, BiometricKycResultDel
extraPartnerParams: args["extraPartnerParams"] as? [String: String] ?? [:],
delegate: self
)
let childViewController = UIHostingController(rootView: screen)

childViewController.view.frame = frame
childViewController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
_view.addSubview(childViewController.view)
let rootViewController = UIApplication.shared.windows.first?.rootViewController
rootViewController?.addChild(childViewController)
_childViewController = childViewController
_childViewController = embedView(screen, in: _view, frame: frame)
}

func view() -> UIView {
Expand Down
9 changes: 1 addition & 8 deletions ios/Classes/SmileIDDocumentVerification.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,7 @@ class SmileIDDocumentVerification : NSObject, FlutterPlatformView, DocumentVerif
extraPartnerParams: args["extraPartnerParams"] as? [String: String] ?? [:],
delegate: self
)
let childViewController = UIHostingController(rootView: screen)

childViewController.view.frame = frame
childViewController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
_view.addSubview(childViewController.view)
let rootViewController = UIApplication.shared.windows.first?.rootViewController
rootViewController?.addChild(childViewController)
_childViewController = childViewController
_childViewController = embedView(screen, in: _view, frame: frame)
}

func view() -> UIView {
Expand Down
9 changes: 1 addition & 8 deletions ios/Classes/SmileIDEnhancedDocumentVerification.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,7 @@ class SmileIDEnhancedDocumentVerification : NSObject, FlutterPlatformView, Enhan
extraPartnerParams: args["extraPartnerParams"] as? [String: String] ?? [:],
delegate: self
)
let childViewController = UIHostingController(rootView: screen)

childViewController.view.frame = frame
childViewController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
_view.addSubview(childViewController.view)
let rootViewController = UIApplication.shared.windows.first?.rootViewController
rootViewController?.addChild(childViewController)
_childViewController = childViewController
_childViewController = embedView(screen, in: _view, frame: frame)
}

func view() -> UIView {
Expand Down
9 changes: 1 addition & 8 deletions ios/Classes/SmileIDSmartSelfieAuthentication.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,7 @@ class SmileIDSmartSelfieAuthentication : NSObject, FlutterPlatformView, SmartSel
extraPartnerParams: args["extraPartnerParams"] as? [String: String] ?? [:],
delegate: self
)
let childViewController = UIHostingController(rootView: screen)

childViewController.view.frame = frame
childViewController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
_view.addSubview(childViewController.view)
let rootViewController = UIApplication.shared.windows.first?.rootViewController
rootViewController?.addChild(childViewController)
_childViewController = childViewController
_childViewController = embedView(screen, in: _view, frame: frame)
}

func view() -> UIView {
Expand Down
9 changes: 1 addition & 8 deletions ios/Classes/SmileIDSmartSelfieEnrollment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,7 @@ class SmileIDSmartSelfieEnrollment : NSObject, FlutterPlatformView, SmartSelfieR
extraPartnerParams: args["extraPartnerParams"] as? [String: String] ?? [:],
delegate: self
)
let childViewController = UIHostingController(rootView: screen)

childViewController.view.frame = frame
childViewController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
_view.addSubview(childViewController.view)
let rootViewController = UIApplication.shared.windows.first?.rootViewController
rootViewController?.addChild(childViewController)
_childViewController = childViewController
_childViewController = embedView(screen, in: _view, frame: frame)
}

func view() -> UIView {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: smile_id
description: The Official Smile ID Flutter SDK
version: 10.1.4
version: 10.1.5
homepage: "https://usesmileid.com"

environment:
Expand Down