@granite-js/react-native 0.1.2 → 0.1.3
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 +14 -0
- package/dist/index.d.ts +1 -0
- package/dist/keyboard/index.d.ts +1 -0
- package/dist/status-bar/StatusBar.android.d.ts +3 -0
- package/dist/status-bar/StatusBar.ios.d.ts +3 -0
- package/dist/status-bar/index.d.ts +2 -0
- package/dist/status-bar/types.d.ts +20 -0
- package/dist/status-bar/utils.d.ts +3 -0
- package/package.json +8 -8
- package/src/index.ts +1 -0
- package/src/keyboard/index.ts +1 -0
- package/src/status-bar/StatusBar.android.tsx +36 -0
- package/src/status-bar/StatusBar.d.ts +4 -0
- package/src/status-bar/StatusBar.ios.tsx +34 -0
- package/src/status-bar/index.ts +2 -0
- package/src/status-bar/types.ts +21 -0
- package/src/status-bar/utils.ts +20 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @granite-js/react-native
|
|
2
2
|
|
|
3
|
+
## 0.1.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 1adad4c: add StatusBar API
|
|
8
|
+
- a4783c8: expose keyboard utils
|
|
9
|
+
- @granite-js/cli@0.1.3
|
|
10
|
+
- @granite-js/image@0.1.3
|
|
11
|
+
- @granite-js/jest@0.1.3
|
|
12
|
+
- @granite-js/lottie@0.1.3
|
|
13
|
+
- @granite-js/mpack@0.1.3
|
|
14
|
+
- @granite-js/native@0.1.3
|
|
15
|
+
- @granite-js/style-utils@0.1.3
|
|
16
|
+
|
|
3
17
|
## 0.1.2
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -15,5 +15,6 @@ export * from './react';
|
|
|
15
15
|
export * from './router/createRoute';
|
|
16
16
|
export * from './event';
|
|
17
17
|
export * from './video';
|
|
18
|
+
export * from './status-bar';
|
|
18
19
|
export type { InitialProps, ColorPreference } from './initial-props';
|
|
19
20
|
export type { GraniteProps } from './app';
|
package/dist/keyboard/index.d.ts
CHANGED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { StatusBarProps } from './types';
|
|
2
|
+
export declare function StatusBar({ style, animated, hidden, backgroundColor, translucent }: StatusBarProps): import("react/jsx-runtime").JSX.Element;
|
|
3
|
+
export declare function useStatusBar({ style, animated, hidden, backgroundColor, translucent }: StatusBarProps): void;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type StatusBarStyle = 'light' | 'dark' | 'auto' | 'inverted';
|
|
2
|
+
export type StatusBarProps = {
|
|
3
|
+
/**
|
|
4
|
+
* @default 'auto'
|
|
5
|
+
*/
|
|
6
|
+
style?: StatusBarStyle;
|
|
7
|
+
hidden?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* @platform android
|
|
10
|
+
*/
|
|
11
|
+
animated?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* @platform android
|
|
14
|
+
*/
|
|
15
|
+
backgroundColor?: string;
|
|
16
|
+
/**
|
|
17
|
+
* @platform android
|
|
18
|
+
*/
|
|
19
|
+
translucent?: boolean;
|
|
20
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@granite-js/react-native",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "The Granite Framework",
|
|
5
5
|
"bin": {
|
|
6
6
|
"granite": "./bin/cli.js"
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"@babel/core": "^7.24.9",
|
|
57
57
|
"@babel/preset-env": "^7.24.8",
|
|
58
58
|
"@babel/preset-typescript": "^7.24.7",
|
|
59
|
-
"@granite-js/native": "0.1.
|
|
59
|
+
"@granite-js/native": "0.1.3",
|
|
60
60
|
"@testing-library/dom": "^10.4.0",
|
|
61
61
|
"@testing-library/react": "^16.1.0",
|
|
62
62
|
"@types/babel__core": "^7",
|
|
@@ -82,12 +82,12 @@
|
|
|
82
82
|
"react-native": "*"
|
|
83
83
|
},
|
|
84
84
|
"dependencies": {
|
|
85
|
-
"@granite-js/cli": "0.1.
|
|
86
|
-
"@granite-js/image": "0.1.
|
|
87
|
-
"@granite-js/jest": "0.1.
|
|
88
|
-
"@granite-js/lottie": "0.1.
|
|
89
|
-
"@granite-js/mpack": "0.1.
|
|
90
|
-
"@granite-js/style-utils": "0.1.
|
|
85
|
+
"@granite-js/cli": "0.1.3",
|
|
86
|
+
"@granite-js/image": "0.1.3",
|
|
87
|
+
"@granite-js/jest": "0.1.3",
|
|
88
|
+
"@granite-js/lottie": "0.1.3",
|
|
89
|
+
"@granite-js/mpack": "0.1.3",
|
|
90
|
+
"@granite-js/style-utils": "0.1.3",
|
|
91
91
|
"es-toolkit": "^1.34.1",
|
|
92
92
|
"react-native-url-polyfill": "1.3.0"
|
|
93
93
|
}
|
package/src/index.ts
CHANGED
|
@@ -17,6 +17,7 @@ export * from './react';
|
|
|
17
17
|
export * from './router/createRoute';
|
|
18
18
|
export * from './event';
|
|
19
19
|
export * from './video';
|
|
20
|
+
export * from './status-bar';
|
|
20
21
|
|
|
21
22
|
export type { InitialProps, ColorPreference } from './initial-props';
|
|
22
23
|
export type { GraniteProps } from './app';
|
package/src/keyboard/index.ts
CHANGED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { useLayoutEffect } from 'react';
|
|
2
|
+
import { StatusBar as BaseStatusBar, useColorScheme } from 'react-native';
|
|
3
|
+
import type { StatusBarProps } from './types';
|
|
4
|
+
import { toStatusBarContentStyle } from './utils';
|
|
5
|
+
|
|
6
|
+
export function StatusBar({ style, animated, hidden, backgroundColor, translucent = true }: StatusBarProps) {
|
|
7
|
+
const colorScheme = useColorScheme() ?? 'light';
|
|
8
|
+
const translucentWithNoBackgroundColor = translucent && backgroundColor == null;
|
|
9
|
+
|
|
10
|
+
return (
|
|
11
|
+
<BaseStatusBar
|
|
12
|
+
translucent={translucent}
|
|
13
|
+
barStyle={toStatusBarContentStyle(style, colorScheme)}
|
|
14
|
+
backgroundColor={translucentWithNoBackgroundColor ? 'transparent' : backgroundColor}
|
|
15
|
+
animated={animated}
|
|
16
|
+
hidden={hidden}
|
|
17
|
+
/>
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function useStatusBar({ style, animated, hidden, backgroundColor, translucent = true }: StatusBarProps) {
|
|
22
|
+
const colorScheme = useColorScheme() ?? 'light';
|
|
23
|
+
const translucentWithNoBackgroundColor = translucent && backgroundColor == null;
|
|
24
|
+
|
|
25
|
+
useLayoutEffect(() => {
|
|
26
|
+
BaseStatusBar.setTranslucent(translucent);
|
|
27
|
+
BaseStatusBar.setBarStyle(toStatusBarContentStyle(style, colorScheme));
|
|
28
|
+
BaseStatusBar.setBackgroundColor(
|
|
29
|
+
translucentWithNoBackgroundColor ? 'transparent' : (backgroundColor ?? 'transparent')
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
if (hidden !== undefined) {
|
|
33
|
+
BaseStatusBar.setHidden(hidden);
|
|
34
|
+
}
|
|
35
|
+
}, [colorScheme, translucentWithNoBackgroundColor, style, animated, hidden, backgroundColor, translucent]);
|
|
36
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { useLayoutEffect } from 'react';
|
|
2
|
+
import { useColorScheme } from 'react-native';
|
|
3
|
+
import type { StatusBarProps } from './types';
|
|
4
|
+
import { toStatusBarContentStyle } from './utils';
|
|
5
|
+
import { useNavigation } from '../router/createRoute';
|
|
6
|
+
|
|
7
|
+
export function StatusBar(props: StatusBarProps) {
|
|
8
|
+
useStatusBar(props);
|
|
9
|
+
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function useStatusBar({ style, hidden }: StatusBarProps) {
|
|
14
|
+
const navigation = useNavigation();
|
|
15
|
+
const colorScheme = useColorScheme() ?? 'light';
|
|
16
|
+
|
|
17
|
+
useLayoutEffect(() => {
|
|
18
|
+
let statusBarStyle: 'light' | 'dark';
|
|
19
|
+
|
|
20
|
+
switch (toStatusBarContentStyle(style, colorScheme)) {
|
|
21
|
+
case 'light-content':
|
|
22
|
+
statusBarStyle = 'light';
|
|
23
|
+
break;
|
|
24
|
+
case 'dark-content':
|
|
25
|
+
statusBarStyle = 'dark';
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
navigation.setOptions({
|
|
30
|
+
statusBarStyle,
|
|
31
|
+
statusBarHidden: hidden,
|
|
32
|
+
});
|
|
33
|
+
}, [navigation, colorScheme, style, hidden]);
|
|
34
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type StatusBarStyle = 'light' | 'dark' | 'auto' | 'inverted';
|
|
2
|
+
|
|
3
|
+
export type StatusBarProps = {
|
|
4
|
+
/**
|
|
5
|
+
* @default 'auto'
|
|
6
|
+
*/
|
|
7
|
+
style?: StatusBarStyle;
|
|
8
|
+
hidden?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* @platform android
|
|
11
|
+
*/
|
|
12
|
+
animated?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* @platform android
|
|
15
|
+
*/
|
|
16
|
+
backgroundColor?: string;
|
|
17
|
+
/**
|
|
18
|
+
* @platform android
|
|
19
|
+
*/
|
|
20
|
+
translucent?: boolean;
|
|
21
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { StatusBarStyle } from './types';
|
|
2
|
+
import type { ColorPreference } from '../initial-props';
|
|
3
|
+
|
|
4
|
+
export function toStatusBarContentStyle(
|
|
5
|
+
statusBarStyle: StatusBarStyle = 'auto',
|
|
6
|
+
colorPreference: ColorPreference = 'light'
|
|
7
|
+
): 'light-content' | 'dark-content' {
|
|
8
|
+
const resolvedStyle = (() => {
|
|
9
|
+
switch (statusBarStyle) {
|
|
10
|
+
case 'auto':
|
|
11
|
+
return colorPreference === 'light' ? 'dark' : 'light';
|
|
12
|
+
case 'inverted':
|
|
13
|
+
return colorPreference === 'light' ? 'light' : 'dark';
|
|
14
|
+
default:
|
|
15
|
+
return statusBarStyle;
|
|
16
|
+
}
|
|
17
|
+
})();
|
|
18
|
+
|
|
19
|
+
return resolvedStyle === 'light' ? 'light-content' : 'dark-content';
|
|
20
|
+
}
|