Skip to content

Commit 9844a5d

Browse files
committed
add useKeyboard example
1 parent 1a1a3f4 commit 9844a5d

7 files changed

+132
-116
lines changed

Diff for: package-lock.json

+81-107
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
"android": "ns run android --env.watchNodeModules",
99
"ios": "ns run ios --env.watchNodeModules",
1010
"android:debug": "ns debug android --env.watchNodeModules",
11-
"ios:debug": "ns debug ios --env.watchNodeModules",
12-
"postinstall": "npm link ../publish"
11+
"ios:debug": "ns debug ios --env.watchNodeModules"
1312
},
1413
"dependencies": {
1514
"@nativescript/core": "^8.5.3",
16-
"@vallemar/nativescript-vueuse": "^0.0.12",
15+
"@vallemar/nativescript-vueuse": "^0.0.13",
1716
"nativescript-vue": "3.0.0-beta.8"
1817
},
1918
"devDependencies": {
File renamed without changes.

Diff for: src/views/Home.vue

+10-4
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import {
44
} from 'nativescript-vue';
55
import ElementSizeView from "./ElementSizeView.vue";
66
import ColorModeView from "./ColorModeView.vue";
7-
import EventListenerComponent from "./EventListenerComponent.vue";
7+
import EventListenerView from "./EventListenerView.vue";
88
import RootLayoutView from './RootLayoutView.vue';
9-
import ScreenOrientationComponent from './ScreenOrientationComponent.vue';
9+
import ScreenOrientationView from './ScreenOrientationView.vue';
1010
import CustomPage from '@/components/CustomPage.vue';
11+
import KeyboardView from './KeyboardView.vue';
1112
import { useColorPalette } from '@vallemar/nativescript-vueuse';
1213
import { Patelle } from '~/data';
1314
15+
1416
const { palette } = useColorPalette<string, Patelle>()
1517
1618
function onUseElementSize() {
@@ -21,17 +23,20 @@ function onUseColorMode() {
2123
}
2224
2325
function onUseEventListener() {
24-
$navigateTo(EventListenerComponent)
26+
$navigateTo(EventListenerView)
2527
}
2628
2729
function onUseRootLayout() {
2830
$navigateTo(RootLayoutView)
2931
}
3032
3133
function onUseScreenOrientation() {
32-
$navigateTo(ScreenOrientationComponent)
34+
$navigateTo(ScreenOrientationView)
3335
}
3436
37+
function onUseKeyboard() {
38+
$navigateTo(KeyboardView)
39+
}
3540
</script>
3641

3742
<template>
@@ -43,6 +48,7 @@ function onUseScreenOrientation() {
4348
<Button @tap="onUseElementSize" text="Use Element Size" class="mt-12 m-1"></Button>
4449
<Button @tap="onUseColorMode" text="Use Color Mode" class="mt-8 m-1"></Button>
4550
<Button @tap="onUseEventListener" text="Use Event Listener" class="mt-8 m-1"></Button>
51+
<Button @tap="onUseKeyboard" text="Use Keyboard" class="mt-8 m-1"></Button>
4652
<Button @tap="onUseRootLayout" text="Use Root Layout" class="mt-8 m-1"></Button>
4753
<Button @tap="onUseScreenOrientation" text="Use Screen Orientation" class="mt-8 m-1"></Button>
4854
</StackLayout>

Diff for: src/views/KeyboardView.vue

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<script lang="ts" setup>
2+
import CustomPage from "@/components/CustomPage.vue";
3+
import { ref } from "nativescript-vue";
4+
import { useKeyboard } from "@vallemar/nativescript-vueuse";
5+
6+
const el = ref()
7+
8+
const { isOpen, open, close } = useKeyboard({
9+
onChange: (isOpenKeyboard: boolean) => {
10+
console.log("Keyboard onChange " + isOpenKeyboard);
11+
},
12+
defaultTarget: el
13+
});
14+
15+
const openKeyboard = () => open()
16+
</script>
17+
18+
<template>
19+
<CustomPage>
20+
<StackLayout class="p-3">
21+
<Label class="text-center text-2xl">Keyboard example</Label>
22+
23+
<FlexboxLayout class=" justify-center items-center mt-10">
24+
<Label class="text-center text-lg bg-variant rounded-2xl p-10">Reactive status {{ isOpen }}</Label>
25+
</FlexboxLayout>
26+
<TextField ref="el" class="bg-variant rounded-full mt-8 pl-3 ios:py-2" hint="Write on me ✍️" />
27+
<Button @tap="openKeyboard()" class="mx-1 mt-8 w-1/2" text="Open keyboard"></Button>
28+
<Button @tap="close" class="mx-1 mt-8 w-1/2" text="Close keyboard"></Button>
29+
</StackLayout>
30+
</CustomPage>
31+
</template>
File renamed without changes.

Diff for: tailwind.config.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1-
/** @type {import('tailwindcss').Config} */
1+
const plugin = require("tailwindcss/plugin");
2+
23
module.exports = {
34
content: ['./src/**/*.{css,xml,html,vue,svelte,ts,tsx}'],
45
// use the .ns-dark class to control dark mode (applied by NativeScript) - since 'media' (default) is not supported.
56
darkMode: ['class', '.ns-dark'],
67
theme: {
78
extend: {},
89
},
9-
plugins: [],
10+
plugins: [
11+
plugin(function ({ addVariant }) {
12+
addVariant("ios", ".ns-ios &");
13+
addVariant("android", ".ns-android &");
14+
}),
15+
],
1016
corePlugins: {
1117
preflight: false, // disables browser-specific resets
1218
},

0 commit comments

Comments
 (0)