Skip to content

Commit cfbf83d

Browse files
committed
1 parent 885f60d commit cfbf83d

File tree

2 files changed

+160
-1
lines changed

2 files changed

+160
-1
lines changed

samples/app/344.js

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
const Vue = require('./nativescript-vue')
2+
const VueDevtools = require('nativescript-vue-devtools')
3+
Vue.use(VueDevtools)
4+
Vue.config.debug = true
5+
Vue.config.silent = false
6+
7+
const CustomButton = {
8+
template: `<Button :text='text' @tap='$emit("tap", $event)' />`,
9+
props: ['text']
10+
}
11+
12+
let step1_id = 0
13+
const Step1 = {
14+
template: `
15+
<Page class="page">
16+
<ActionBar title="Home" class="action-bar" />
17+
<StackLayout>
18+
<StackLayout>
19+
<Label class="m-t-30" text="Welcome to step 1!" />
20+
21+
<CustomButton text="This button only works if you stay on this tab" @tap="next" />
22+
23+
<CustomButton text="This button always works" @tap.native="next" />
24+
</StackLayout>
25+
</StackLayout>
26+
</Page>
27+
`,
28+
components: { CustomButton },
29+
30+
created() {
31+
console.log('Step 1 created.')
32+
},
33+
34+
beforeDestroy() {
35+
console.log('Destroying step 1...')
36+
},
37+
38+
destroyed() {
39+
console.log('Step 1 destroyed.')
40+
},
41+
42+
methods: {
43+
next() {
44+
this.$navigateTo(Step2, { frame: 'second' })
45+
}
46+
}
47+
}
48+
49+
const Step2 = {
50+
template: `
51+
<Page class="page">
52+
<ActionBar title="Home" class="action-bar" />
53+
<StackLayout>
54+
<Label text="Welcome to step 2!" />
55+
<Button text="Great, time for step 3." @tap="next" />
56+
</StackLayout>
57+
</Page>
58+
`,
59+
created() {
60+
console.log('Step 2 created.')
61+
},
62+
beforeDestroy() {
63+
console.log('Destroying step 2...')
64+
},
65+
destroyed() {
66+
console.log('Step 2 destroyed.')
67+
},
68+
methods: {
69+
next() {
70+
this.$navigateTo(Step3, { frame: 'second' })
71+
}
72+
}
73+
}
74+
75+
const Step3 = {
76+
template: `
77+
<Page class="page">
78+
<ActionBar title="Home" class="action-bar" />
79+
<StackLayout>
80+
<Label text="You made it to the last step!" />
81+
<Button text="Cool, start over." @tap="reset" />
82+
</StackLayout>
83+
</Page>
84+
`,
85+
created() {
86+
console.log('Step 3 created.')
87+
},
88+
beforeDestroy() {
89+
console.log('Destroying step 3...')
90+
},
91+
destroyed() {
92+
console.log('Step 3 destroyed.')
93+
},
94+
methods: {
95+
reset() {
96+
this.$navigateTo(Step1, { frame: 'second', clearHistory: true })
97+
}
98+
}
99+
}
100+
101+
const FirstTab = {
102+
template: `
103+
<Page class="page">
104+
<ActionBar title="Home" class="action-bar" />
105+
<StackLayout>
106+
<Label class="m-t-30" textWrap="true" text="Tap on the second tab, then tap on this tab, and tap back over to the second tab. The top button will no longer work on the second tab's page."
107+
/>
108+
</StackLayout>
109+
</Page>
110+
`
111+
}
112+
113+
const TabBar = {
114+
template: `
115+
<GridLayout rows="*">
116+
<!--<keep-alive>-->
117+
<Frame id="first" v-show="screen == 0" key="0">
118+
<FirstTab />
119+
</Frame>
120+
<Frame id="second" v-show="screen == 1" key="1">
121+
<Step1 />
122+
</Frame>
123+
<!--</keep-alive>-->
124+
125+
<StackLayout class="tabbar" orientation="horizontal" row="0">
126+
<Label class="tabbar__item" @tap="screen = 0" text="First" :class='{"tabbar__item--active": screen == 0}' />
127+
<Label class="tabbar__item" @tap="screen = 1" text="Second" :class='{"tabbar__item--active": screen == 1}' />
128+
</StackLayout>
129+
</GridLayout>
130+
`,
131+
components: { FirstTab, Step1 },
132+
133+
data() {
134+
return {
135+
screen: 0
136+
}
137+
}
138+
}
139+
140+
new Vue({
141+
render: h => h(TabBar)
142+
}).$start()

samples/app/app.css

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,21 @@
2626
@keyframes fade {
2727
from { opacity: 0; }
2828
to { opacity: 1; }
29-
}
29+
}
30+
31+
.tabbar {
32+
width: 100%;
33+
vertical-align: bottom;
34+
background-color: #eaeaea;
35+
}
36+
37+
.tabbar__item {
38+
padding: 20 0;
39+
width: 50%;
40+
text-align: center;
41+
vertical-align: center;
42+
}
43+
44+
.tabbar__item--active {
45+
color: #5577dd;
46+
}

0 commit comments

Comments
 (0)