Skip to content

Commit d2856b9

Browse files
feat(frame and page): added frame and page component wrappers
This change should allow a frame which is not topmost to still navigate a child page
1 parent fefe407 commit d2856b9

File tree

8 files changed

+82
-13
lines changed

8 files changed

+82
-13
lines changed

platform/nativescript/element-registry.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,11 @@ registerElement(
127127
'NativeNavigationButton',
128128
() => require('tns-core-modules/ui/action-bar').NavigationButton
129129
)
130-
registerElement('Page', () => require('tns-core-modules/ui/page').Page, {
130+
131+
registerElement('NativePage', () => require('tns-core-modules/ui/page').Page, {
131132
skipAddToDom: true
132133
})
134+
133135
registerElement(
134136
'Placeholder',
135137
() => require('tns-core-modules/ui/placeholder').Placeholder
@@ -271,10 +273,14 @@ registerElement(
271273
}
272274
)
273275

274-
registerElement('Frame', () => require('tns-core-modules/ui/frame').Frame, {
275-
insertChild(parentNode, childNode, atIndex) {
276-
if (childNode.tagName === 'page') {
277-
parentNode.nativeView.navigate({ create: () => childNode.nativeView })
278-
}
276+
registerElement(
277+
'NativeFrame',
278+
() => require('tns-core-modules/ui/frame').Frame,
279+
{
280+
// insertChild(parentNode, childNode, atIndex) {
281+
// if (childNode.tagName === 'page' || childNode.tagName === 'nativepage') {
282+
// parentNode.nativeView.navigate({ create: () => childNode.nativeView })
283+
// }
284+
// }
279285
}
280-
})
286+
)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
export default {
2+
template: `<NativeFrame :ref="reference" v-bind="$attrs" v-on="$listeners">>
3+
<slot></slot>
4+
</NativeFrame>`,
5+
data() {
6+
return {
7+
reference: Math.random()
8+
.toString(36)
9+
.substring(2, 15),
10+
context: ''
11+
}
12+
},
13+
mounted() {
14+
let THIS = this
15+
this.context = this.$refs[this.reference]
16+
17+
this.$on('page_has_been_loaded', function(context) {
18+
THIS.context.nativeView.navigate(
19+
Object.assign(
20+
{},
21+
{
22+
create() {
23+
return context.nativeView // should be the page
24+
}
25+
}
26+
)
27+
)
28+
})
29+
}
30+
}

platform/nativescript/runtime/components/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import TabView from './tab-view'
88
import TabViewItem from './tab-view-item'
99
import transition from './transition'
1010
import VTemplate from './v-template'
11+
import Frame from './Frame'
12+
import Page from './Page'
1113

1214
export default {
1315
ActionBar,
@@ -19,5 +21,7 @@ export default {
1921
TabView,
2022
TabViewItem,
2123
transition,
22-
VTemplate
24+
VTemplate,
25+
Frame,
26+
Page
2327
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
export default {
2+
template: `<NativePage :ref="reference" v-bind="$attrs" v-on="$listeners">
3+
<slot></slot>
4+
</NativePage>`,
5+
data() {
6+
return {
7+
reference: Math.random()
8+
.toString(36)
9+
.substring(2, 15),
10+
context: null
11+
}
12+
},
13+
mounted() {
14+
let THIS = this
15+
this.context = this.$refs[this.reference]
16+
17+
this.$nextTick(function() {
18+
THIS.$parent.$parent.$emit('page_has_been_loaded', this.context)
19+
})
20+
}
21+
}

samples/app/app-with-android-ios.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,8 @@ new Vue({
1515
</StackLayout>
1616
</Page>
1717
`
18-
}).$start()
18+
}).$start({
19+
getRootView(self) {
20+
return self.$el.nativeView // frame
21+
}
22+
})

samples/app/app-with-router-v2.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ const Detail = {
2121
<Page>
2222
<GridLayout rows="*, *, *">
2323
<Label :text="'Detail for ' + $route.params.id" row="0"/>
24-
<Button text="Tab 2" @tap="$router.replace($route.path + '/tab2')"/>
24+
<Button row="1" text="Tab 2" @tap="$router.replace($route.path + '/tab2')"/>
2525
26-
<router-view row="1" />
26+
<router-view row="2" />
2727
</GridLayout>
2828
</Page>
2929
`

samples/app/app-with-router.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,8 @@ new Vue({
9191
router.replace(to)
9292
}
9393
}
94-
}).$start()
94+
}).$start({
95+
getRootView(vm) {
96+
return vm.$el.nativeView
97+
}
98+
})

samples/app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"main": "app-with-frames.js",
2+
"main": "app-with-router-v2.js",
33
"name": "nativescript-template-tutorial",
44
"version": "1.0.1"
55
}

0 commit comments

Comments
 (0)