-
Notifications
You must be signed in to change notification settings - Fork 2
[MOO-2398] - Migrate to scene delegate lifecycle #64
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
Open
YogendraShelke
wants to merge
2
commits into
mx/11.12.x
Choose a base branch
from
moo/MOO-2398-scene-delegate-migration
base: mx/11.12.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,41 +1,9 @@ | ||
| import UIKit | ||
| import React | ||
| import MendixNative | ||
|
|
||
| @main | ||
| class AppDelegate: ReactAppProvider { | ||
| class AppDelegate: UIResponder, UIApplicationDelegate { | ||
|
|
||
| override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { | ||
| setUpProvider() | ||
| guard let bundleUrl = bundleURL() else { | ||
| let message = "No script URL provided. Make sure the metro packager is running or you have embedded a JS bundle in your application bundle." | ||
| fatalError(message) | ||
| } | ||
| let mendixApp = MendixApp.init( | ||
| identifier: nil, | ||
| bundleUrl: bundleUrl, | ||
| runtimeUrl: URL(string: "http://localhost:8081")!, | ||
| warningsFilter: .none, | ||
| isDeveloperApp: true, | ||
| clearDataAtLaunch: false, | ||
| splashScreenPresenter: nil, | ||
| reactLoading: nil, | ||
| enableThreeFingerGestures: false | ||
| ) | ||
|
|
||
| AppPreferences.devModeEnabled = true | ||
| AppPreferences.remoteDebuggingEnabled = true | ||
|
|
||
| ReactNative.shared.setup(mendixApp, launchOptions: nil) | ||
| ReactNative.shared.start() | ||
| return super.application(application, didFinishLaunchingWithOptions: launchOptions) | ||
| } | ||
|
|
||
| func bundleURL() -> URL? { | ||
| #if DEBUG | ||
| RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index") | ||
| #else | ||
| Bundle.main.url(forResource: "main", withExtension: "jsbundle") | ||
| #endif | ||
| func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool { | ||
| return true | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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,39 @@ | ||
| import UIKit | ||
| import React | ||
| import MendixNative | ||
|
|
||
| class SceneDelegate: ReactAppProvider { | ||
|
|
||
| override func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { | ||
| super.scene(scene, willConnectTo: session, options: connectionOptions) | ||
|
|
||
| setUpProvider() | ||
| guard let bundleUrl = bundleURL() else { | ||
| let message = "No script URL provided. Make sure the metro packager is running or you have embedded a JS bundle in your application bundle." | ||
| fatalError(message) | ||
| } | ||
| let mendixApp = MendixApp.init( | ||
| identifier: nil, | ||
| bundleUrl: bundleUrl, | ||
| runtimeUrl: URL(string: "http://localhost:8081")!, | ||
| warningsFilter: .none, | ||
| isDeveloperApp: true, | ||
| clearDataAtLaunch: false, | ||
| splashScreenPresenter: nil, | ||
| reactLoading: nil, | ||
| enableThreeFingerGestures: false | ||
| ) | ||
| AppPreferences.devModeEnabled = true | ||
| AppPreferences.remoteDebuggingEnabled = true | ||
| ReactNative.shared.setup(mendixApp, launchOptions: ReactAppProvider.launchOptions(from: connectionOptions)) | ||
| ReactNative.shared.start() | ||
| } | ||
|
|
||
| func bundleURL() -> URL? { | ||
| #if DEBUG | ||
| RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index") | ||
| #else | ||
| Bundle.main.url(forResource: "main", withExtension: "jsbundle") | ||
| #endif | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're not using the ReactAppProvider it looks like we need to have get/set for a
windowproperty onUIApplication.shared.delegate- RN tries to access it inRCTDeviceInfo::_interfaceOrientationDidChangeand apparently won't check if that one is missing so we'll get a crash.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that you already have this in Native Template, but wonder if it's best to have it here instead so MiN can benefit as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the suggestion is to keep this in mendix-native and then reuse it in native-template and make-it-native, we would need to introduce a separate class containing this property and extend AppDelegate on both platforms. While that would work, it also adds additional boilerplate, and maintaining a dedicated class for a single property feels a bit excessive for the use case.
If, instead, you're referring to adding it directly in example/ios/MendixNativeExample/AppDelegate.swift, that unfortunately would not be a viable solution because the example app is only a sample application and is not distributed as part of mendix-native. As a result, any changes made there would not be available to consumers of the library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to have it in mendix-native and reuse, but i agree that would add more abstraction layers. Alternative is if course to duplicate this logic in both Native Template and MiN and remember to keep it update this also doesn't sound like a great option 😅