Skip to content

Commit 016c64f

Browse files
Hristo HristovHristo Hristov
authored andcommitted
showModal & closeModal can be called on any View
fix livesync implementation to be compatible with 3.4 and to replace mainEntry for 4.0 when root is not Frame some refactoring of page.ios in order to allow showing multiple modal dialogs
1 parent 9dd3e1a commit 016c64f

File tree

20 files changed

+341
-135
lines changed

20 files changed

+341
-135
lines changed

apps/app/modaltest/app.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Button {
2+
background-color: red
3+
}

apps/app/modaltest/main-page.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Frame>
2+
<Page backgroundColor="blue" loaded='onNavigatingTo'>
3+
<ActionBar>
4+
<Label text='MIDDLE TEXT' backgroundColor='green' />
5+
</ActionBar> -->
6+
<!-- <TabView backgroundColor="green">
7+
<TabViewItem title="Item One"> -->
8+
<!-- <ScrollView backgroundColor="purple"> -->
9+
<StackLayout backgroundColor="orange" verticalAlignment="center">
10+
<Button text="LiveSync" tap="sync" />
11+
<Button text="Show Modal TabView" tap="onModalTab" />
12+
<Button text="Show Modal Frame" tap="onModalFrame" />
13+
<Button text="requestLayout for titleView" tap="onTap3" />
14+
</StackLayout>
15+
<!-- </ScrollView> -->
16+
<!-- </TabViewItem>
17+
</TabView> -->
18+
</Page>
19+
</Frame>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Page backgroundColor="pink" codeFile='~/page.2' actionBarHidden="true">
2+
<Frame>
3+
<Page backgroundColor="purple">
4+
<ActionBar title=" AAA ">
5+
<!-- <ActionBar title="{{ $value, 'Page ' + $value }} "> -->
6+
<ActionItem text="close" tap="closeModal" ios.position='right' />
7+
</ActionBar>
8+
<StackLayout backgroundColor="orange">
9+
<Button text="FORWARD" tap="onTap"/>
10+
<Button text="BACKWARD" tap="onBack"/>
11+
</StackLayout>
12+
</Page>
13+
</Frame>
14+
</Page>

apps/app/modaltest/modal-frame.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Frame codeFile='~/page.2'>
2+
<Page backgroundColor="pink">
3+
<ActionBar title="{{ $value, 'Page ' + $value }} ">
4+
<ActionItem text="close" tap="closeModal" ios.position='right' />
5+
</ActionBar>
6+
<StackLayout backgroundColor="orange">
7+
<Button text="FORWARD" tap="onTap"/>
8+
<Button text="BACKWARD" tap="onBack"/>
9+
<Button text="showModal" tap="showModal"/>
10+
</StackLayout>
11+
</Page>
12+
</Frame>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<Page backgroundColor="blue" actionBarHidden="true" loaded="pageLoaded"
2+
codeFile='~/modal-tab'>
3+
<ActionBar title="Frame in Modal Page">
4+
<ActionItem text="close" tap="closeModal" />
5+
</ActionBar>
6+
<TabView backgroundColor="magenta">
7+
<TabViewItem title="Button">
8+
<StackLayout verticalAlignment="center" backgroundColor="green" verticalAlignment="bottom" horizontalAlignment="right">
9+
<Button text="Close Modal" tap="tap" />
10+
<Button text="Show Modal Frame" tap="onModalFrame" />
11+
</StackLayout>
12+
</TabViewItem>
13+
<TabViewItem title="Frame">
14+
<ScrollView backgroundColor="cyan">
15+
<StackLayout backgroundColor="pink" verticalAlignment="bottom" >
16+
<Label text="I'm frame in modal page" />
17+
<Label text="Tap the button" />
18+
<Button text="TAP" tap="onTap" />
19+
<Button text="Do 10 go backs" tap="tenGoBacks" />
20+
<Button text="Navigate To Page with Frame" tap="navigateToPageWithFrame" />
21+
</StackLayout>
22+
</ScrollView>
23+
</TabViewItem>
24+
<TabViewItem title="Item 3">
25+
<ScrollView>
26+
<StackLayout verticalAlignment="bottom" horizontalAlignment="right">
27+
<Button text="Close Modal" tap="tap" />
28+
<Button text="Show Modal Frame" tap="onModalFrame" />
29+
</StackLayout>
30+
</ScrollView>
31+
</TabViewItem>
32+
</TabView>
33+
</Page>

apps/app/modaltest/modal-tab.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Button {
2+
background-color: white
3+
}

apps/app/modaltest/modal-tab.xml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<TabView backgroundColor="red" loaded="onLoaded">
2+
<TabViewItem title="Button">
3+
<StackLayout backgroundColor="orange"
4+
verticalAlignment="bottom"
5+
horizontalAlignment="right">
6+
<Button text="LIVESYNC" tap="onLiveSync" />
7+
<Button text="Close Modal" tap="tap" />
8+
<Button text="new Frame" tap="newFrame" />
9+
<Button text="Show Modal Frame" tap="onModalFrame" />
10+
<TextView text="text viesw" />
11+
<TextField text="text field" />
12+
<TextField text="text field" />
13+
<Button text="Button" />
14+
</StackLayout>
15+
</TabViewItem>
16+
<TabViewItem title="Frame">
17+
<Frame backgroundColor="green">
18+
<Page backgroundColor="blue" actionBarHidden="true" loaded="pageLoaded">
19+
<Page.actionBar>
20+
<ActionBar title="Frame in Modal Page" />
21+
<ActionItem text="close" tap="closeModal" />
22+
</Page.actionBar>
23+
<ScrollView backgroundColor="cyan">
24+
<StackLayout backgroundColor="pink" verticalAlignment="bottom" >
25+
<Label text="I'm frame in modal page" />
26+
<Label text="Tap the button" />
27+
<Button text="TAP" tap="onTap" />
28+
<Button text="Do 10 go backs" tap="tenGoBacks" />
29+
<Button text="Navigate To Page with Frame" tap="navigateToPageWithFrame" />
30+
</StackLayout>
31+
</ScrollView>
32+
</Page>
33+
</Frame>
34+
</TabViewItem>
35+
<TabViewItem title="Item 3">
36+
<ScrollView>
37+
<StackLayout verticalAlignment="bottom" horizontalAlignment="right">
38+
<Button text="Close Modal" tap="tap" />
39+
<Button text="Show Modal Frame" tap="onModalFrame" />
40+
</StackLayout>
41+
</ScrollView>
42+
</TabViewItem>
43+
</TabView>

apps/app/modaltest/page.2.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Page backgroundColor="pink" showingModally="showingModally">
2+
<ActionBar title="{{ $value, 'Page ' + $value }} ">
3+
<ActionItem text="close" tap="closeModal" ios.position='right' />
4+
</ActionBar>
5+
<StackLayout backgroundColor="orange">
6+
<Button text="{{ $value, Modal Page: $value }}" />
7+
<Button text="FORWARD" tap="onTap"/>
8+
<Button text="BACKWARD" tap="onBack"/>
9+
<Button text="Do 10 go backs" tap="tenGoBacks" />
10+
<Button text="Show Modal" tap="showModal"/>
11+
<Button text="Close Modal" tap="closeModal"/>
12+
<Button text="Livesync" tap="onLivesync"/>
13+
</StackLayout>
14+
</Page>

apps/app/modaltest/textview.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Frame>
2+
<Page backgroundColor="blue" >
3+
<StackLayout backgroundColor="orange" verticalAlignment="top">
4+
<Button text="set text" tap='tap' />
5+
<TextView text="text" />
6+
</StackLayout>
7+
</Page>
8+
</Frame>

tns-core-modules/application/application.ios.ts

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export * from "./application-common";
1616

1717
// TODO: Remove this and get it from global to decouple builder for angular
1818
import { createViewFromEntry } from "../ui/builder";
19-
import { ios as iosView, ViewBase } from "../ui/core/view";
20-
import { Frame, View, NavigationEntry } from "../ui/frame";
19+
import { ios as iosView, View } from "../ui/core/view";
20+
import { Frame, NavigationEntry } from "../ui/frame";
2121
import { ios } from "../ui/utils";
2222
import * as utils from "../utils/utils";
2323
import { profile } from "../profiling";
@@ -51,7 +51,7 @@ class IOSApplication implements IOSApplicationDefinition {
5151
private _currentOrientation = utils.ios.getter(UIDevice, UIDevice.currentDevice).orientation;
5252
private _window: UIWindow;
5353
private _observers: Array<NotificationObserver>;
54-
private _rootView: ViewBase;
54+
private _rootView: View;
5555

5656
constructor() {
5757
this._observers = new Array<NotificationObserver>();
@@ -114,18 +114,7 @@ class IOSApplication implements IOSApplicationDefinition {
114114
notify(args);
115115
notify(<LoadAppCSSEventData>{ eventName: "loadAppCss", object: <any>this, cssFile: getCssFileName() });
116116

117-
const rootView = createRootView(args.root);
118-
this._rootView = rootView;
119-
const controller = getViewController(rootView);
120-
this._window.rootViewController = controller;
121-
if (createRootFrame) {
122-
// Don't setup as styleScopeHost
123-
rootView._setupUI({});
124-
} else {
125-
// setup view as styleScopeHost
126-
rootView._setupAsRootView({});
127-
}
128-
this._window.makeKeyAndVisible();
117+
this.setWindowContent(args.root);
129118
}
130119

131120
@profile
@@ -193,12 +182,44 @@ class IOSApplication implements IOSApplicationDefinition {
193182
});
194183
}
195184
}
185+
186+
public _onLivesync(): void {
187+
// If view can't handle livesync set window controller.
188+
if (!this._rootView._onLivesync()) {
189+
this.setWindowContent();
190+
}
191+
}
192+
193+
public setWindowContent(view?: View): void {
194+
const rootView = createRootView(view);
195+
this._rootView = rootView;
196+
const controller = getViewController(rootView);
197+
198+
if (createRootFrame) {
199+
// Don't setup as styleScopeHost
200+
rootView._setupUI({});
201+
} else {
202+
// setup view as styleScopeHost
203+
rootView._setupAsRootView({});
204+
}
205+
206+
const haveController = this._window.rootViewController !== null;
207+
this._window.rootViewController = controller;
208+
if (!haveController) {
209+
this._window.makeKeyAndVisible();
210+
}
211+
}
196212
}
197213

198214
const iosApp = new IOSApplication();
199215
exports.ios = iosApp;
200216
setApplication(iosApp);
201217

218+
// attach on global, so it can be overwritten in NativeScript Angular
219+
(<any>global).__onLiveSyncCore = function () {
220+
iosApp._onLivesync();
221+
}
222+
202223
let mainEntry: NavigationEntry;
203224
function createRootView(v?: View) {
204225
let rootView = v;

0 commit comments

Comments
 (0)