Skip to content

Commit e77cd12

Browse files
committed
Use useBottomSheet to access global funcs
1 parent 92dee9d commit e77cd12

File tree

4 files changed

+15
-29
lines changed

4 files changed

+15
-29
lines changed

demo-snippets/vue3/BottomSheet.vue

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
import { EventData, View } from '@nativescript/core';
1919
import * as frameModule from '@nativescript/core/ui/frame';
2020
import { NativeScriptVue } from 'nativescript-vue';
21-
import { inject } from 'vue';
2221
import BottomSheetInner from './BottomSheetInner.vue';
2322
import BottomSheetInnerKeyboard from './BottomSheetInnerKeyboard.vue';
23+
import { useBottomSheet } from "@nativescript-community/ui-material-bottomsheet/vue3";
2424
2525
const title = 'BottomSheet sample';
2626
const name = 'BottomSheet';
27-
const $showBottomSheet = inject('$showBottomSheet')
2827
28+
const { showBottomSheet, closeBottomSheet } = useBottomSheet()
2929
function onNavigationButtonTap() {
3030
frameModule.Frame.topmost().goBack();
3131
}
@@ -36,7 +36,7 @@ function onTap(args: EventData) {
3636
console.log('onTap', objId, obj);
3737
switch (objId) {
3838
case 'bottomsheet': {
39-
$showBottomSheet(BottomSheetInner, {
39+
showBottomSheet(BottomSheetInner, {
4040
// transparent: true,
4141
on: {
4242
indexChanged: (x) => { console.log('listener', x) }
@@ -48,7 +48,7 @@ function onTap(args: EventData) {
4848
break;
4949
}
5050
case 'dont_ignore_top_safe_area': {
51-
$showBottomSheet(BottomSheetInner, {
51+
showBottomSheet(BottomSheetInner, {
5252
ignoreTopSafeArea: false,
5353
// transparent:true,
5454
closeCallback: (...args) => {
@@ -58,7 +58,7 @@ function onTap(args: EventData) {
5858
break;
5959
}
6060
case 'ignore_bottom_safe_area': {
61-
$showBottomSheet(BottomSheetInner, {
61+
showBottomSheet(BottomSheetInner, {
6262
// transparent:true,
6363
ignoreBottomSafeArea: true,
6464
closeCallback: (...args) => {
@@ -68,7 +68,7 @@ function onTap(args: EventData) {
6868
break;
6969
}
7070
case 'dont_ignore_top_ignore_bottom_safe_area': {
71-
$showBottomSheet(BottomSheetInner, {
71+
showBottomSheet(BottomSheetInner, {
7272
// transparent:true,
7373
ignoreTopSafeArea: false,
7474
ignoreBottomSafeArea: true,
@@ -79,15 +79,15 @@ function onTap(args: EventData) {
7979
break;
8080
}
8181
case 'bottomsheet-keyboard': {
82-
$showBottomSheet(BottomSheetInnerKeyboard, {
82+
showBottomSheet(BottomSheetInnerKeyboard, {
8383
closeCallback: (...args) => {
8484
console.log('bottom sheet closed', args);
8585
}
8686
});
8787
break;
8888
}
8989
case 'bottomsheet-peekheight': {
90-
$showBottomSheet(BottomSheetInner, {
90+
showBottomSheet(BottomSheetInner, {
9191
peekHeight: 100,
9292
trackingScrollView: 'scrollView',
9393
// transparent: true,

demo-snippets/vue3/BottomSheetInner.vue

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,6 @@
1212
<MDTextField hint="Edit text to filter..." style="font-size: 16" />
1313
<MDActivityIndicator *ngIf="processing" width="50" height="50" />
1414
</StackLayout>
15-
<ListView height="150" :items="items" id="scrollView">
16-
<v-template let-item="item" let-odd="odd" let-even="even">
17-
<GridLayout height="64" backgroundColor="green">
18-
<Image horizontalAlignment="left" width="64" />
19-
<Label horizontalAlignment="center" />
20-
<Label horizontalAlignment="right" />
21-
</GridLayout>
22-
</v-template>
23-
</ListView>
2415
<Button text="Cancel" horizontalAlignment="center" />
2516
</StackLayout>
2617
</GridLayout>
@@ -30,16 +21,14 @@
3021
<script lang="ts" setup>
3122
import * as frameModule from '@nativescript/core/ui/frame';
3223
import BottomSheetInnerKeyboardVue from './BottomSheetInnerKeyboard.vue';
33-
import { inject } from 'vue';
34-
35-
const $closeBottomSheet = inject('$closeBottomSheet');
36-
const $showBottomSheet = inject('$showBottomSheet');
24+
import { useBottomSheet } from "@nativescript-community/ui-material-bottomsheet/vue3";
25+
const { showBottomSheet, closeBottomSheet } = useBottomSheet()
3726
3827
const showExtraContent = false;
3928
const items = [{}, {}, {}, {}, {}, {}]
4029
4130
function onButtonTap(event) {
42-
$closeBottomSheet(event.object.id);
31+
closeBottomSheet(event.object.id);
4332
}
4433
4534
function onShownInBottomSheet(args) {
@@ -51,7 +40,7 @@ function toggleExtraContent() {
5140
}
5241
5342
function openAnotherInner() {
54-
$showBottomSheet(BottomSheetInnerKeyboardVue, {
43+
showBottomSheet(BottomSheetInnerKeyboardVue, {
5544
// transparent:true,
5645
ignoreBottomSafeArea: true,
5746
closeCallback: (...args) => {

demo-snippets/vue3/BottomSheetInnerKeyboard.vue

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@
1010

1111
<script lang="ts" setup>
1212
import * as frameModule from '@nativescript/core/ui/frame';
13-
import { inject } from 'vue';
14-
15-
const $closeBottomSheet = inject('$closeBottomSheet');
13+
import { useBottomSheet } from "@nativescript-community/ui-material-bottomsheet/vue3";
14+
const { showBottomSheet, closeBottomSheet } = useBottomSheet()
1615
1716
function onShownInBottomSheet(args) {
1817
console.log('onShownInBottomSheet');
1918
}
2019
2120
function onButtonTap(event) {
22-
$closeBottomSheet(event.object.id);
21+
closeBottomSheet(event.object.id);
2322
}
2423
</script>

src/bottomsheet/vue3/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ const BottomSheetPlugin = {
7777

7878
globals.$showBottomSheet = showSheet;
7979
globals.$closeBottomSheet = closeSheet;
80-
app.provide('$showBottomSheet', showSheet);
81-
app.provide('$closeBottomSheet', closeSheet);
8280
}
8381
};
8482

0 commit comments

Comments
 (0)