8000 feat: updated $showModal · shirakaba/nativescript-vue@b2be4bd · GitHub
[go: up one dir, main page]

Skip to content

Commit b2be4bd

Browse files
committed
feat: updated $showModal
1 parent a5085f1 commit b2be4bd

File tree

92 files changed

+191
-124
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+191
-124
lines changed

platform/nativescript/plugins/modal-plugin.js

Lines changed: 59 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,72 @@
1-
import { ensurePage } from '../util'
1+
function _findParentModalEntry(vm) {
2+
if (!vm) {
3+
return false
4+
}
5+
6+
let entry = vm.$parent
7+
while (entry && entry.$options.name !== 'ModalEntry') {
8+
entry = entry.$parent
9+
}
10+
11+
return entry
12+
}
213

314
export default {
415
install(Vue) {
5-
Vue.prototype.$showModal = function(
6-
component,
7-
options = { context: null, fullscreen: false }
8-
) {
16+
Vue.mixin({
17+
created() {
18+
const self = this
19+
this.$modal = {
20+
close(data) {
21+
const entry = _findParentModalEntry(self)
22+
23+
if (entry) {
24+
entry.closeCb(data)
25+
}
26+
}
27+
}
28+
}
29+
})
30+
31+
Vue.prototype.$showModal = function(component, options) {
32+
const defaultOptions = {
33+
fullscreen: false
34+
}
35+
// build options object with defaults
36+
options = Object.assign({}, defaultOptions, options)
37+
938
return new Promise(resolve => {
10-
const contentComponent = Vue.extend(component)
11-
const vm = new contentComponent(options.context)
39+
let resolved = false
40+
const closeCb = data => {
41+
if (resolved) return
1242

13-
vm.$mount()
14-
const modalPage = ensurePage(vm.$el, vm)
43+
resolved = true
44+
resolve(data)
45+
modalPage.closeModal()
1546

16-
contentComponent.prototype.$modal = {
17-
close(data) {
18-
resolve(data)
19-
modalPage.closeModal()
20-
}
47+
// emitted to show up in devtools
48+
// for debugging purposes
49+
navEntryInstance.$emit('modal:close', data)
50+
navEntryInstance.$destroy()
2151
}
2252

23-
this.$root.$el.nativeView.showModal(
53+
const navEntryInstance = new Vue({
54+
name: 'ModalEntry',
55+
parent: this.$root,
56+
methods: {
57+
closeCb
58+
},
59+
render: h =>
60+
h(component, {
61+
props: options.props
62+
})
63+
})
64+
const modalPage = navEntryInstance.$mount().$el.nativeView
65+
66+
this.$el.nativeView.showModal(
2467
modalPage,
2568
null,
26-
vm.$modal.close,
69+
closeCb,
2770
options.fullscreen
2871
)
2972
})

platform/nativescript/plugins/navigator-plugin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ function _findParentNavigationEntry(vm) {
3434

3535
export default {
3636
install(Vue) {
37-
Vue.prototype.$navigateBack = function(options) {
37+
Vue.prototype.$navigateBack = function(options, backstackEntry = null) {
3838
const navEntry = _findParentNavigationEntry(this)
3939
const defaultOptions = {
4040
frame: navEntry ? navEntry.$options.frame : 'default'
4141
}
4242
options = Object.assign({}, defaultOptions, options)
4343
const frame = getFrameInstance(options.frame)
4444

45-
frame.back()
45+
frame.back(backstackEntry)
4646
}
4747

4848
Vue.prototype.$navigateTo = function(component, options) {

samples/app/App_Resources/Android/AndroidManifest.xml

Lines changed: 0 additions & 43 deletions
This file was deleted.

samples/app/App_Resources/Android/app.gradle

100755100644
Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
11
// Add your native dependencies here:
22

3-
// Uncomment to add recyclerview-v7 dependency
4-
//dependencies {
5-
// compile 'com.android.support:recyclerview-v7:+'
6-
//}
7-
8-
android {
3+
android {
94
defaultConfig {
105
generatedDensities = []
11-
applicationId = "org.nativescript.vuesample"
12-
13-
//override supported platforms
14-
// ndk {
15-
// abiFilters.clear()
16-
// abiFilters "armeabi-v7a"
17-
// }
18-
19-
}
6+
applicationId = "org.nativescript.application"
7+
}
208
aaptOptions {
219
additionalParameters "--no-version-vectors"
2210
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)
0