Skip to content

Commit

Permalink
Fix navigation bug on iOS (#89)
Browse files Browse the repository at this point in the history
* 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
jumaallan and tobitech authored Jul 19, 2024
1 parent 15684d4 commit bd46e14
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 43 deletions.
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

0 comments on commit bd46e14

Please sign in to comment.