Skip to content

Commit 9d6cf64

Browse files
committed
add useScreenOrientation
1 parent 91a9159 commit 9d6cf64

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
},
1414
"dependencies": {
1515
"@nativescript/core": "^8.5.3",
16-
"@vallemar/nativescript-vueuse": "^0.0.11",
16+
"@vallemar/nativescript-vueuse": "^0.0.12",
1717
"nativescript-vue": "3.0.0-beta.8"
1818
},
1919
"devDependencies": {

src/components/Home.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import ElementSizeView from "~/components/ElementSizeView.vue";
77
import ColorModeView from "~/components/ColorModeView.vue";
88
import EventListenerComponent from "~/components/EventListenerComponent.vue";
99
import RootLayoutView from './rootLayout/RootLayoutView.vue';
10+
import ScreenOrientationComponent from './ScreenOrientationComponent.vue';
1011
1112
function onUseElementSize() {
1213
$navigateTo(ElementSizeView)
@@ -23,6 +24,10 @@ function onUseRootLayout() {
2324
$navigateTo(RootLayoutView)
2425
}
2526
27+
function onUseScreenOrientation() {
28+
$navigateTo(ScreenOrientationComponent)
29+
}
30+
2631
</script>
2732

2833
<template>
@@ -35,6 +40,7 @@ function onUseRootLayout() {
3540
<Button @tap="onUseColorMode" text="Use Color Mode" class="mt-8 m-1"></Button>
3641
<Button @tap="onUseEventListener" text="Use Event Listener" class="mt-8 m-1"></Button>
3742
<Button @tap="onUseRootLayout" text="Use Root Layout" class="mt-8 m-1"></Button>
43+
<Button @tap="onUseScreenOrientation" text="Use Screen Orientation" class="mt-8 m-1"></Button>
3844
</StackLayout>
3945
</Page>
4046
</Frame>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<script lang="ts" setup>
2+
import { useScreenOrientation } from '@vallemar/nativescript-vueuse';
3+
4+
const {
5+
orientation,
6+
setOrientation,
7+
enableRotation,
8+
disableRotation
9+
} = useScreenOrientation({
10+
onChange: (orientation) => {
11+
console.log("useScreenOrientation onChange " + orientation);
12+
}
13+
})
14+
15+
</script>
16+
17+
<template>
18+
<Page actionBarHidden="true">
19+
<ScrollView>
20+
<StackLayout class="p-3">
21+
<Label class="text-center text-2xl">ScreenOrientation {{ orientation }}</Label>
22+
<Button @tap="setOrientation('portrait')" class="mx-1 mt-8" text="Set portrait"></Button>
23+
<Button @tap="setOrientation('landscape')" class="mx-1 mt-8" text="Set landscape"></Button>
24+
<Button @tap="setOrientation('landscapeleft')" class="mx-1 mt-8" text="Set landscapeleft"></Button>
25+
<Button @tap="setOrientation('landscaperight')" class="mx-1 mt-8" text="Set landscaperight"></Button>
26+
<Button @tap="enableRotation" class="mx-1 mt-8" text="Enable rotation"></Button>
27+
<Button @tap="disableRotation" class="mx-1 mt-8" text="Disable rotation"></Button>
28+
</StackLayout>
29+
</ScrollView>
30+
</Page>
31+
</template>

0 commit comments

Comments
 (0)