@granite-js/react-native 1.0.17 → 1.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @granite-js/react-native
|
|
2
2
|
|
|
3
|
+
## 1.0.18
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 96fe7c1: Use Android keyboard show/hide events in New Architecture for `useKeyboardAnimatedHeight`.
|
|
8
|
+
- @granite-js/blur-view@1.0.18
|
|
9
|
+
- @granite-js/cli@1.0.18
|
|
10
|
+
- @granite-js/jest@1.0.18
|
|
11
|
+
- @granite-js/mpack@1.0.18
|
|
12
|
+
- @granite-js/native@1.0.18
|
|
13
|
+
- @granite-js/plugin-core@1.0.18
|
|
14
|
+
- @granite-js/style-utils@1.0.18
|
|
15
|
+
- @granite-js/video@1.0.18
|
|
16
|
+
|
|
3
17
|
## 1.0.17
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -5,7 +5,7 @@ import { Animated } from 'react-native';
|
|
|
5
5
|
* @description
|
|
6
6
|
* A Hook that returns an animatable value (`Animated.Value`) representing the keyboard height changes when the keyboard appears or disappears. You can smoothly animate UI elements according to the keyboard height as it rises or falls.
|
|
7
7
|
*
|
|
8
|
-
* This Hook
|
|
8
|
+
* This Hook uses `keyboardWillShow`/`keyboardWillHide` on iOS, and `keyboardDidShow`/`keyboardDidHide` on Android when React Native New Architecture is enabled. On Android Old Architecture, it always returns an `Animated.Value` with an initial value of `0`.
|
|
9
9
|
*
|
|
10
10
|
* @returns {Animated.Value} - An animation value representing the keyboard height.
|
|
11
11
|
* @example
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isNewArchEnabled(): boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@granite-js/react-native",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.18",
|
|
4
4
|
"description": "The Granite Framework",
|
|
5
5
|
"bin": {
|
|
6
6
|
"granite": "./bin/cli.js"
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"@babel/core": "7.28.5",
|
|
92
92
|
"@babel/preset-env": "7.28.5",
|
|
93
93
|
"@babel/preset-typescript": "7.28.5",
|
|
94
|
-
"@granite-js/native": "1.0.
|
|
94
|
+
"@granite-js/native": "1.0.18",
|
|
95
95
|
"@testing-library/dom": "^10.4.0",
|
|
96
96
|
"@testing-library/react": "^16.1.0",
|
|
97
97
|
"@types/babel__core": "^7",
|
|
@@ -113,20 +113,20 @@
|
|
|
113
113
|
"zod": "^4.1.12"
|
|
114
114
|
},
|
|
115
115
|
"peerDependencies": {
|
|
116
|
-
"@granite-js/native": "1.0.
|
|
116
|
+
"@granite-js/native": "1.0.18",
|
|
117
117
|
"@types/react": "*",
|
|
118
118
|
"brick-module": "*",
|
|
119
119
|
"react": "*",
|
|
120
120
|
"react-native": "*"
|
|
121
121
|
},
|
|
122
122
|
"dependencies": {
|
|
123
|
-
"@granite-js/blur-view": "1.0.
|
|
124
|
-
"@granite-js/cli": "1.0.
|
|
125
|
-
"@granite-js/jest": "1.0.
|
|
126
|
-
"@granite-js/mpack": "1.0.
|
|
127
|
-
"@granite-js/plugin-core": "1.0.
|
|
128
|
-
"@granite-js/style-utils": "1.0.
|
|
129
|
-
"@granite-js/video": "1.0.
|
|
123
|
+
"@granite-js/blur-view": "1.0.18",
|
|
124
|
+
"@granite-js/cli": "1.0.18",
|
|
125
|
+
"@granite-js/jest": "1.0.18",
|
|
126
|
+
"@granite-js/mpack": "1.0.18",
|
|
127
|
+
"@granite-js/plugin-core": "1.0.18",
|
|
128
|
+
"@granite-js/style-utils": "1.0.18",
|
|
129
|
+
"@granite-js/video": "1.0.18",
|
|
130
130
|
"@standard-schema/spec": "^1.0.0",
|
|
131
131
|
"es-toolkit": "^1.39.8",
|
|
132
132
|
"react-native-url-polyfill": "3.0.0"
|
|
@@ -1,8 +1,27 @@
|
|
|
1
1
|
import { useEffect, useRef } from 'react';
|
|
2
2
|
import { Animated, Keyboard, Platform } from 'react-native';
|
|
3
|
+
import { isNewArchEnabled } from '../utils/isNewArchEnabled';
|
|
4
|
+
|
|
5
|
+
function getKeyboardEventNames() {
|
|
6
|
+
if (Platform.OS === 'ios') {
|
|
7
|
+
return {
|
|
8
|
+
show: 'keyboardWillShow',
|
|
9
|
+
hide: 'keyboardWillHide',
|
|
10
|
+
} as const;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (Platform.OS === 'android' && isNewArchEnabled()) {
|
|
14
|
+
return {
|
|
15
|
+
show: 'keyboardDidShow',
|
|
16
|
+
hide: 'keyboardDidHide',
|
|
17
|
+
} as const;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
3
22
|
|
|
4
23
|
function getInitialKeyboardHeight() {
|
|
5
|
-
if (Platform.OS
|
|
24
|
+
if (Platform.OS === 'android' && !isNewArchEnabled()) {
|
|
6
25
|
return 0;
|
|
7
26
|
}
|
|
8
27
|
|
|
@@ -26,7 +45,7 @@ function getInitialKeyboardHeight() {
|
|
|
26
45
|
* @description
|
|
27
46
|
* A Hook that returns an animatable value (`Animated.Value`) representing the keyboard height changes when the keyboard appears or disappears. You can smoothly animate UI elements according to the keyboard height as it rises or falls.
|
|
28
47
|
*
|
|
29
|
-
* This Hook
|
|
48
|
+
* This Hook uses `keyboardWillShow`/`keyboardWillHide` on iOS, and `keyboardDidShow`/`keyboardDidHide` on Android when React Native New Architecture is enabled. On Android Old Architecture, it always returns an `Animated.Value` with an initial value of `0`.
|
|
30
49
|
*
|
|
31
50
|
* @returns {Animated.Value} - An animation value representing the keyboard height.
|
|
32
51
|
* @example
|
|
@@ -42,31 +61,34 @@ export function useKeyboardAnimatedHeight(): Animated.Value {
|
|
|
42
61
|
const keyboardHeight = useRef(new Animated.Value(getInitialKeyboardHeight())).current;
|
|
43
62
|
|
|
44
63
|
useEffect(() => {
|
|
45
|
-
|
|
46
|
-
const willShowSubscription = Keyboard.addListener('keyboardWillShow', (event) => {
|
|
47
|
-
const height = event.endCoordinates.height;
|
|
64
|
+
const keyboardEventNames = getKeyboardEventNames();
|
|
48
65
|
|
|
49
|
-
|
|
50
|
-
toValue: height,
|
|
51
|
-
useNativeDriver: true,
|
|
52
|
-
...spring.quick,
|
|
53
|
-
}).start();
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
const willHideSubscription = Keyboard.addListener('keyboardWillHide', () => {
|
|
57
|
-
Animated.spring(keyboardHeight, {
|
|
58
|
-
toValue: 0,
|
|
59
|
-
useNativeDriver: true,
|
|
60
|
-
...spring.quick,
|
|
61
|
-
}).start();
|
|
62
|
-
});
|
|
63
|
-
return () => {
|
|
64
|
-
willShowSubscription.remove();
|
|
65
|
-
willHideSubscription.remove();
|
|
66
|
-
};
|
|
67
|
-
} else {
|
|
66
|
+
if (keyboardEventNames == null) {
|
|
68
67
|
return;
|
|
69
68
|
}
|
|
69
|
+
|
|
70
|
+
const showSubscription = Keyboard.addListener(keyboardEventNames.show, (event) => {
|
|
71
|
+
const height = event.endCoordinates.height;
|
|
72
|
+
|
|
73
|
+
Animated.spring(keyboardHeight, {
|
|
74
|
+
toValue: height,
|
|
75
|
+
useNativeDriver: true,
|
|
76
|
+
...spring.quick,
|
|
77
|
+
}).start();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const hideSubscription = Keyboard.addListener(keyboardEventNames.hide, () => {
|
|
81
|
+
Animated.spring(keyboardHeight, {
|
|
82
|
+
toValue: 0,
|
|
83
|
+
useNativeDriver: true,
|
|
84
|
+
...spring.quick,
|
|
85
|
+
}).start();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
return () => {
|
|
89
|
+
showSubscription.remove();
|
|
90
|
+
hideSubscription.remove();
|
|
91
|
+
};
|
|
70
92
|
}, [keyboardHeight]);
|
|
71
93
|
|
|
72
94
|
return keyboardHeight;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function isNewArchEnabled() {
|
|
2
|
+
const globalObject = globalThis as typeof globalThis & {
|
|
3
|
+
RN$Bridgeless?: boolean;
|
|
4
|
+
nativeFabricUIManager?: unknown;
|
|
5
|
+
__turboModuleProxy?: unknown;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
return (
|
|
9
|
+
globalObject.RN$Bridgeless === true ||
|
|
10
|
+
globalObject.nativeFabricUIManager != null ||
|
|
11
|
+
globalObject.__turboModuleProxy != null
|
|
12
|
+
);
|
|
13
|
+
}
|