| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 67f9e06 commit 05c2460
9 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,6 +5,7 @@ libs | |||
| 5 | 5 | node_modules | |
| 6 | 6 | package | |
| 7 | 7 | platforms | |
| 8 | + !tns-core-modules/platforms | ||
| 8 | 9 | reports | |
| 9 | 10 | tags | |
| 10 | 11 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -131,16 +131,26 @@ class IOSApplication implements IOSApplicationDefinition { | |||
| 131 | 131 | // TODO: Expose Window module so that it can we styled from XML & CSS | |
| 132 | 132 | this._window.backgroundColor = utils.ios.getter(UIColor, UIColor.whiteColor); | |
| 133 | 133 | ||
| 134 | + this.notifyAppStarted(notification); | ||
| 135 | + | ||
| 136 | + } | ||
| 137 | + | ||
| 138 | + public notifyAppStarted(notification?: NSNotification) { | ||
| 134 | 139 | const args: LaunchEventData = { | |
| 135 | 140 | eventName: launchEvent, | |
| 136 | 141 | object: this, | |
| 137 | - ios: notification.userInfo && notification.userInfo.objectForKey("UIApplicationLaunchOptionsLocalNotificationKey") || null | ||
| 142 | + ios: notification && notification.userInfo && notification.userInfo.objectForKey("UIApplicationLaunchOptionsLocalNotificationKey") || null | ||
| 138 | 143 | }; | |
| 139 | 144 | ||
| 140 | 145 | notify(args); | |
| 141 | 146 | notify(<LoadAppCSSEventData>{ eventName: "loadAppCss", object: <any>this, cssFile: getCssFileName() }); | |
| 142 | 147 | ||
| 143 | - this.setWindowContent(args.root); | ||
| 148 | + // this._window will be undefined when NS app is embedded in a native one | ||
| 149 | + if (this._window) { | ||
| 150 | + this.setWindowContent(args.root); | ||
| 151 | + } else { | ||
| 152 | + this._window = UIApplication.sharedApplication.delegate.window; | ||
| 153 | + } | ||
| 144 | 154 | } | |
| 145 | 155 | ||
| 146 | 156 | @profile | |
@@ -235,6 +245,7 @@ class IOSApplication implements IOSApplicationDefinition { | |||
| 235 | 245 | this._window.makeKeyAndVisible(); | |
| 236 | 246 | } | |
| 237 | 247 | } | |
| 248 | + | ||
| 238 | 249 | } | |
| 239 | 250 | ||
| 240 | 251 | const iosApp = new IOSApplication(); | |
@@ -296,7 +307,14 @@ export function start(entry?: string | NavigationEntry) { | |||
| 296 | 307 | if (rootController) { | |
| 297 | 308 | const controller = getViewController(rootView); | |
| 298 | 309 | rootView._setupAsRootView({}); | |
| 299 | - rootController.presentViewControllerAnimatedCompletion(controller, true, null); | ||
| 310 | + let embedderDelegate = NativeScriptEmbedder.sharedInstance().delegate; | ||
| 311 | + if (embedderDelegate) { | ||
| 312 | + embedderDelegate.performSelectorWithObject("presentNativeScriptApp:", controller); | ||
| 313 | + } else { | ||
| 314 | + let visibleVC = utils.ios.getVisibleViewController(rootController); | ||
| 315 | + visibleVC.presentViewControllerAnimatedCompletion(controller, true, null); | ||
| 316 | + } | ||
| 317 | + iosApp.notifyAppStarted(); | ||
| 300 | 318 | } | |
| 301 | 319 | } | |
| 302 | 320 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + ## Platform specific native code | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,26 @@ | |||
| 1 | + // | ||
| 2 | + // NativeScriptEmbedder.h | ||
| 3 | + // NativeScript | ||
| 4 | + // | ||
| 5 | + // Created by Teodor Dermendzhiev on 6/19/18. | ||
| 6 | + // | ||
| 7 | + #include <UIKit/UIKit.h> | ||
| 8 | + | ||
| 9 | + // When embedding NativeScript application embedder needs to conform to this protocol | ||
| 10 | + // in order to have control over the NativeScript UIViewController | ||
| 11 | + // otherwise NativeScript application is presented over the topmost UIViewController. | ||
| 12 | + @protocol NativeScriptEmbedderDelegate | ||
| 13 | + - (id)presentNativeScriptApp:(UIViewController*)vc; | ||
| 14 | + @end | ||
| 15 | + | ||
| 16 | + @interface NativeScriptEmbedder : NSObject | ||
| 17 | + | ||
| 18 | + @property(nonatomic, retain, readonly) id<NativeScriptEmbedderDelegate> delegate; | ||
| 19 | + | ||
| 20 | + + (NativeScriptEmbedder *)sharedInstance; | ||
| 21 | + | ||
| 22 | + - (void)setDelegate:(id <NativeScriptEmbedderDelegate>)aDelegate; | ||
| 23 | + | ||
| 24 | + | ||
| 25 | + @end | ||
| 26 | + | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,19 @@ | |||
| 1 | + #import "NativeScriptEmbedder.h" | ||
| 2 | + | ||
| 3 | + @implementation NativeScriptEmbedder | ||
| 4 | + | ||
| 5 | + + (NativeScriptEmbedder *)sharedInstance { | ||
| 6 | + static NativeScriptEmbedder *sharedInstance = nil; | ||
| 7 | + static dispatch_once_t onceToken; | ||
| 8 | + dispatch_once(&onceToken, ^{ | ||
| 9 | + sharedInstance = [[NativeScriptEmbedder alloc] init]; | ||
| 10 | + }); | ||
| 11 | + | ||
| 12 | + return sharedInstance; | ||
| 13 | + } | ||
| 14 | + | ||
| 15 | + - (void)setDelegate:(id <NativeScriptEmbedderDelegate>)aDelegate { | ||
| 16 | + _delegate = aDelegate; | ||
| 17 | + } | ||
| 18 | + | ||
| 19 | + @end | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,4 @@ | |||
| 1 | + module NativeScriptEmbedder { | ||
| 2 | + header "NativeScriptEmbedder.h" | ||
| 3 | + export * | ||
| 4 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -160,3 +160,14 @@ interface Array<T> { | |||
| 160 | 160 | //Dialogs | |
| 161 | 161 | declare function alert(message?: any): void; | |
| 162 | 162 | declare function confirm(message?: string): boolean; | |
| 163 | + | ||
| 164 | + // Embedding | ||
| 165 | + declare interface NativeScriptEmbedderDelegate /* NSObject */ { | ||
| 166 | + presentNativeScriptApp(any/* UIViewController*/): any; | ||
| 167 | + performSelectorWithObject(string, any): any; | ||
| 168 | + } | ||
| 169 | + | ||
| 170 | + declare class NativeScriptEmbedder { | ||
| 171 | + public static sharedInstance(): NativeScriptEmbedder; | ||
| 172 | + public delegate: NativeScriptEmbedderDelegate; | ||
| 173 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -247,6 +247,13 @@ export module ios { | |||
| 247 | 247 | * iOS - this folder is read-only and contains the app and all its resources. | |
| 248 | 248 | */ | |
| 249 | 249 | export function getCurrentAppPath(): string; | |
| 250 | + | ||
| 251 | + /** | ||
| 252 | + * Gets the currently visible(topmost) UIViewController. | ||
| 253 | + * @param rootViewController The root UIViewController instance to start searching from (normally window.rootViewController). | ||
| 254 | + * Returns the visible UIViewController. | ||
| 255 | + */ | ||
| 256 | + export function getVisibleViewController(rootViewController: any/* UIViewController*/ ): any/* UIViewController*/; | ||
| 250 | 257 | } | |
| 251 | 258 | ||
| 252 | 259 | /** | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -116,6 +116,25 @@ export module ios { | |||
| 116 | 116 | ||
| 117 | 117 | return NSString.stringWithString(NSString.pathWithComponents(<any>paths)).stringByStandardizingPath; | |
| 118 | 118 | } | |
| 119 | + | ||
| 120 | + export function getVisibleViewController(rootViewController: UIViewController): UIViewController { | ||
| 121 | + if (rootViewController.presentedViewController) { | ||
| 122 | + return getVisibleViewController(rootViewController.presentedViewController); | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + if (rootViewController.isKindOfClass(UINavigationController.class())) { | ||
| 126 | + return getVisibleViewController((<UINavigationController>rootViewController).visibleViewController); | ||
| 127 | + } | ||
| 128 | + | ||
| 129 | + if (rootViewController.isKindOfClass(UITabBarController.class())) { | ||
| 130 | + let selectedTab = (<UITabBarController>rootViewController).selectedViewController; | ||
| 131 | + return getVisibleViewController(<UITabBarController>rootViewController); | ||
| 132 | + } | ||
| 133 | + | ||
| 134 | + return rootViewController; | ||
| 135 | + | ||
| 136 | + } | ||
| 137 | + | ||
| 119 | 138 | } | |
| 120 | 139 | ||
| 121 | 140 | export function GC() { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments