@granite-js/react-native 0.1.34 → 1.0.0

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.
Files changed (88) hide show
  1. package/CHANGELOG.md +12 -573
  2. package/dist/app/Granite.d.ts +2 -2
  3. package/dist/async-bridges.js +6 -6
  4. package/dist/async-bridges.mjs +2 -2
  5. package/dist/chunk-7GFSQK76.mjs +7 -0
  6. package/dist/constant-bridges.js +4 -4
  7. package/dist/constant-bridges.mjs +2 -2
  8. package/dist/image/Image.d.ts +77 -0
  9. package/dist/image/SvgImage.d.ts +47 -0
  10. package/dist/image/index.d.ts +1 -0
  11. package/dist/image/types.d.ts +3 -0
  12. package/dist/index.d.ts +4 -3
  13. package/dist/intersection-observer/IOFlatList.d.ts +2 -2
  14. package/dist/lottie/Lottie.d.ts +22 -0
  15. package/dist/lottie/ensureSafeLottie.d.ts +3 -0
  16. package/dist/lottie/index.d.ts +1 -0
  17. package/dist/lottie/useFetchResource.d.ts +2 -0
  18. package/dist/native-modules/index.d.ts +0 -1
  19. package/dist/native-modules/natives/GraniteBrownfieldModule.brick.d.ts +14 -0
  20. package/dist/router/Router.d.ts +11 -3
  21. package/dist/router/components/CanGoBackGuard.d.ts +2 -1
  22. package/dist/router/components/ErrorBoundary.d.ts +16 -0
  23. package/dist/router/components/StackNavigator.d.ts +40 -43
  24. package/dist/router/components/useRouterBackHandler.d.ts +3 -3
  25. package/dist/router/createRoute.d.ts +4 -1
  26. package/dist/router/hooks/useRouterControls.d.ts +3 -2
  27. package/dist/router/types/ErrorComponent.d.ts +6 -0
  28. package/dist/router/types/RouteScreen.d.ts +6 -0
  29. package/dist/router/types/index.d.ts +1 -0
  30. package/dist/status-bar/utils.d.ts +2 -2
  31. package/dist/video/Video.d.ts +5 -18
  32. package/package.json +22 -19
  33. package/src/app/Granite.tsx +2 -2
  34. package/src/image/Image.tsx +125 -0
  35. package/src/image/SvgImage.tsx +124 -0
  36. package/src/image/index.ts +1 -0
  37. package/src/image/types.ts +6 -0
  38. package/src/index.ts +14 -3
  39. package/src/intersection-observer/IOFlatList.ts +2 -2
  40. package/src/intersection-observer/withIO.tsx +71 -17
  41. package/src/lottie/Lottie.tsx +87 -0
  42. package/src/lottie/ensureSafeLottie.ts +15 -0
  43. package/src/lottie/index.ts +1 -0
  44. package/src/lottie/useFetchResource.ts +31 -0
  45. package/src/native-modules/index.ts +0 -1
  46. package/src/native-modules/natives/GraniteBrownfieldModule.brick.ts +15 -0
  47. package/src/native-modules/natives/closeView.ts +2 -2
  48. package/src/native-modules/natives/getSchemeUri.ts +2 -2
  49. package/src/router/Router.tsx +40 -12
  50. package/src/router/components/CanGoBackGuard.tsx +2 -3
  51. package/src/router/components/ErrorBoundary.tsx +38 -0
  52. package/src/router/components/useRouterBackHandler.tsx +3 -3
  53. package/src/router/createRoute.ts +6 -2
  54. package/src/router/hooks/useRouterControls.tsx +21 -7
  55. package/src/router/types/ErrorComponent.ts +8 -0
  56. package/src/router/types/RouteScreen.ts +6 -0
  57. package/src/router/types/index.ts +1 -0
  58. package/src/router/utils/screen.tsx +2 -0
  59. package/src/status-bar/utils.ts +2 -2
  60. package/src/types/global.ts +1 -1
  61. package/src/video/Video.tsx +6 -17
  62. package/src/visibility/VisibilityProvider.tsx +3 -3
  63. package/src/visibility/utils/usePrevious.tsx +1 -1
  64. package/dist/blur/BlurView.d.ts +0 -78
  65. package/dist/blur/ReactNativeBlurModule.d.ts +0 -6
  66. package/dist/blur/constants.d.ts +0 -1
  67. package/dist/blur/index.d.ts +0 -1
  68. package/dist/chunk-A3JGM5OI.mjs +0 -7
  69. package/dist/native-event-emitter/eventEmitters/index.d.ts +0 -2
  70. package/dist/native-event-emitter/eventEmitters/types.d.ts +0 -4
  71. package/dist/native-event-emitter/eventEmitters/visibilityChanged.d.ts +0 -10
  72. package/dist/native-event-emitter/index.d.ts +0 -1
  73. package/dist/native-event-emitter/nativeEventEmitter.d.ts +0 -15
  74. package/dist/native-modules/core/GraniteCoreModule.d.ts +0 -8
  75. package/dist/native-modules/natives/GraniteModule.d.ts +0 -7
  76. package/dist/video/instance.d.ts +0 -9
  77. package/src/blur/BlurView.tsx +0 -103
  78. package/src/blur/ReactNativeBlurModule.ts +0 -19
  79. package/src/blur/constants.ts +0 -3
  80. package/src/blur/index.ts +0 -1
  81. package/src/native-event-emitter/eventEmitters/index.ts +0 -3
  82. package/src/native-event-emitter/eventEmitters/types.ts +0 -4
  83. package/src/native-event-emitter/eventEmitters/visibilityChanged.ts +0 -11
  84. package/src/native-event-emitter/index.ts +0 -1
  85. package/src/native-event-emitter/nativeEventEmitter.ts +0 -18
  86. package/src/native-modules/core/GraniteCoreModule.ts +0 -9
  87. package/src/native-modules/natives/GraniteModule.ts +0 -8
  88. package/src/video/instance.tsx +0 -28
@@ -1,15 +0,0 @@
1
- import { EmitterSubscription } from 'react-native';
2
- import { EventEmitters } from './eventEmitters';
3
- import { EventEmitterSchema } from './eventEmitters/types';
4
- type MapOf<T> = T extends EventEmitterSchema<infer K, any> ? {
5
- [key in K]: T;
6
- } : never;
7
- type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
8
- type EventEmittersMap = UnionToIntersection<MapOf<EventEmitters>>;
9
- type EventKeys = keyof EventEmittersMap;
10
- type ParamOf<K extends EventKeys> = EventEmittersMap[K]['params'];
11
- interface EventEmitter {
12
- addListener<Event extends EventKeys>(event: Event, callback: (...params: ParamOf<Event>) => void): EmitterSubscription;
13
- }
14
- export declare const nativeEventEmitter: EventEmitter;
15
- export {};
@@ -1,8 +0,0 @@
1
- import { TurboModule } from 'react-native';
2
- interface GraniteCoreModule extends TurboModule {
3
- addListener: (eventType: string) => void;
4
- removeListeners: (count: number) => void;
5
- importLazy: () => Promise<void>;
6
- }
7
- export declare const GraniteCoreModule: GraniteCoreModule;
8
- export {};
@@ -1,7 +0,0 @@
1
- import { TurboModule } from 'react-native';
2
- interface GraniteModuleSpec extends TurboModule {
3
- closeView: () => void;
4
- schemeUri: string;
5
- }
6
- export declare const GraniteModule: GraniteModuleSpec;
7
- export {};
@@ -1,9 +0,0 @@
1
- import type { VideoProperties } from '@granite-js/native/react-native-video';
2
- import { type ComponentType } from 'react';
3
- export type VideoNativeProps = Omit<VideoProperties, 'onAudioFocusChanged'> & {
4
- onAudioFocusChanged?: (event: {
5
- hasAudioFocus: boolean;
6
- }) => void;
7
- };
8
- export declare const Component: ComponentType<VideoNativeProps>;
9
- export declare const isAvailable: boolean;
@@ -1,103 +0,0 @@
1
- import type { BlurViewProps as InternalBlurViewProps } from '@granite-js/native/@react-native-community/blur';
2
- import { View, ViewProps } from 'react-native';
3
- import { ReactNativeBlurModule } from './ReactNativeBlurModule';
4
- import { isBlurNativeModuleSupported } from './constants';
5
-
6
- export type BlurType = InternalBlurViewProps['blurType'];
7
-
8
- export interface BlurViewProps extends ViewProps {
9
- blurType?: BlurType;
10
- blurAmount?: number;
11
- vibrancyEffect?: boolean;
12
- reducedTransparencyFallbackColor?: string;
13
- }
14
-
15
- /**
16
- * @public
17
- * @category UI
18
- * @name BlurView
19
- * @description
20
- * `BlurView` adds a blurred background effect, primarily on iOS. It creates a visual blur on the background view.
21
- *
22
- * This component is supported only on iOS. On Android, it simply renders a regular [`View`](https://reactnative.dev/docs/0.72/view) without any blur effect.
23
- *
24
- * You can control the blur intensity and optionally enable the [vibrancy effect](https://developer.apple.com/documentation/uikit/uivibrancyeffect?language=objc), which enhances the visual impact of content displayed over a blurred background.
25
- *
26
- * If blur is not supported or doesn't render properly, you can use the `reducedTransparencyFallbackColor` prop to set a fallback background color.
27
- *
28
- * Use the `isSupported` property to check whether the current device supports blur. Blur is available on iOS from version 5.126.0 and not supported on Android.
29
- *
30
- * @param {BlurViewProps} [props] The props you can pass to `BlurView`. It extends `react-native`'s `ViewProps`, so you can use layout and style properties. The props align with those of [`@react-native-community/blur`](https://github.com/Kureev/react-native-blur/tree/v4.3.2?tab=readme-ov-file#blurview).
31
- * @param {BlurType} [props.blurType] Type of blur to apply, such as `light`, `dark`, or `extraDark`.
32
- * @param {number} [props.blurAmount=10] Intensity of the blur effect. Higher values make the blur stronger. Accepts values from `0` to `100`. Default is `10`.
33
- * @param {boolean} [props.vibrancyEffect=false] Enables the vibrancy effect. This effect enhances content displayed on top of the blur. Only supported on iOS. Default is `false`.
34
- * @param {string} [props.reducedTransparencyFallbackColor] Fallback background color used when blur cannot be applied due to system settings or device limitations.
35
- *
36
- * @returns {JSX.Element} On iOS, returns a blurred `BlurView` or `VibrancyView` component. On Android, returns a regular `View` without blur.
37
- *
38
- * ::: warning Note
39
- * `BlurView` is only supported on iOS. On Android, it renders a regular `View` without any blur effect.
40
- * :::
41
- *
42
- * @example
43
- *
44
- * ### Blurring background behind a text
45
- *
46
- * ```tsx
47
- * import { BlurView } from '@granite-js/react-native';
48
- * import { View, Text, StyleSheet } from 'react-native';
49
- *
50
- * export function BlurViewExample() {
51
- * return (
52
- * <View style={styles.container}>
53
- * <Text style={styles.absolute}>Blurred Text</Text>
54
- * <BlurView style={styles.absolute} blurType="light" blurAmount={1} />
55
- * <Text>Non Blurred Text</Text>
56
- * </View>
57
- * );
58
- * }
59
- *
60
- * const styles = StyleSheet.create({
61
- * container: {
62
- * justifyContent: 'center',
63
- * alignItems: 'center',
64
- * width: '100%',
65
- * height: 300,
66
- * },
67
- * absolute: {
68
- * position: 'absolute',
69
- * top: 0,
70
- * left: 0,
71
- * bottom: 0,
72
- * right: 0,
73
- * },
74
- * });
75
- * ```
76
- *
77
- * @see [iOS Vibrancy Effect Documentation](https://developer.apple.com/documentation/uikit/uivibrancyeffect)
78
- * @see [Zeddios Blog Explanation](https://zeddios.tistory.com/1140)
79
- */
80
- export function BlurView({
81
- blurType,
82
- blurAmount = 10,
83
- reducedTransparencyFallbackColor,
84
- vibrancyEffect = false,
85
- ...viewProps
86
- }: BlurViewProps) {
87
- if (!isBlurNativeModuleSupported || ReactNativeBlurModule == null) {
88
- return <View {...viewProps} />;
89
- }
90
-
91
- const Component = vibrancyEffect ? ReactNativeBlurModule.VibrancyView : ReactNativeBlurModule.BlurView;
92
-
93
- return (
94
- <Component
95
- blurAmount={blurAmount}
96
- blurType={blurType}
97
- reducedTransparencyFallbackColor={reducedTransparencyFallbackColor}
98
- {...viewProps}
99
- />
100
- );
101
- }
102
-
103
- BlurView.isSupported = isBlurNativeModuleSupported;
@@ -1,19 +0,0 @@
1
- import type { BlurView, VibrancyView } from '@granite-js/native/@react-native-community/blur';
2
- import { isBlurNativeModuleSupported } from './constants';
3
-
4
- const ReactNativeBlurModule = (() => {
5
- if (!isBlurNativeModuleSupported) {
6
- return undefined;
7
- }
8
-
9
- try {
10
- return require('@granite-js/native/@react-native-community/blur') as {
11
- BlurView: typeof BlurView;
12
- VibrancyView: typeof VibrancyView;
13
- };
14
- } catch {
15
- return undefined;
16
- }
17
- })();
18
-
19
- export { ReactNativeBlurModule };
@@ -1,3 +0,0 @@
1
- import { Platform } from 'react-native';
2
-
3
- export const isBlurNativeModuleSupported = Platform.OS === 'ios';
package/src/blur/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './BlurView';
@@ -1,3 +0,0 @@
1
- import { VisibilityChangedEventEmitter } from './visibilityChanged';
2
-
3
- export type EventEmitters = VisibilityChangedEventEmitter;
@@ -1,4 +0,0 @@
1
- export interface EventEmitterSchema<K extends string, P extends unknown[]> {
2
- name: K;
3
- params: P;
4
- }
@@ -1,11 +0,0 @@
1
- import { EventEmitterSchema } from './types';
2
-
3
- /**
4
- * @name VisibilityChangedEventEmitter
5
- * @kind typedef
6
- * @platform iOS
7
- * @description
8
- * Emits an event when the visibility state of the app changes.
9
- * Only available on iOS.
10
- */
11
- export type VisibilityChangedEventEmitter = EventEmitterSchema<'visibilityChanged', [boolean]>;
@@ -1 +0,0 @@
1
- export * from './nativeEventEmitter';
@@ -1,18 +0,0 @@
1
- import { EmitterSubscription, NativeEventEmitter } from 'react-native';
2
- import { EventEmitters } from './eventEmitters';
3
- import { GraniteCoreModule } from '../native-modules';
4
- import { EventEmitterSchema } from './eventEmitters/types';
5
-
6
- type MapOf<T> = T extends EventEmitterSchema<infer K, any> ? { [key in K]: T } : never;
7
- type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
8
- type EventEmittersMap = UnionToIntersection<MapOf<EventEmitters>>;
9
- type EventKeys = keyof EventEmittersMap;
10
- type ParamOf<K extends EventKeys> = EventEmittersMap[K]['params'];
11
- interface EventEmitter {
12
- addListener<Event extends EventKeys>(
13
- event: Event,
14
- callback: (...params: ParamOf<Event>) => void
15
- ): EmitterSubscription;
16
- }
17
-
18
- export const nativeEventEmitter = new NativeEventEmitter(GraniteCoreModule) as unknown as EventEmitter;
@@ -1,9 +0,0 @@
1
- import { TurboModule, TurboModuleRegistry } from 'react-native';
2
-
3
- interface GraniteCoreModule extends TurboModule {
4
- addListener: (eventType: string) => void;
5
- removeListeners: (count: number) => void;
6
- importLazy: () => Promise<void>;
7
- }
8
-
9
- export const GraniteCoreModule = TurboModuleRegistry.getEnforcing<GraniteCoreModule>('GraniteCoreModule');
@@ -1,8 +0,0 @@
1
- import { TurboModule, TurboModuleRegistry } from 'react-native';
2
-
3
- interface GraniteModuleSpec extends TurboModule {
4
- closeView: () => void;
5
- schemeUri: string;
6
- }
7
-
8
- export const GraniteModule = TurboModuleRegistry.getEnforcing<GraniteModuleSpec>('GraniteModule');
@@ -1,28 +0,0 @@
1
- import type { VideoProperties } from '@granite-js/native/react-native-video';
2
- import { Component as ReactComponent, forwardRef, type ComponentType, type ForwardedRef } from 'react';
3
- import { View } from 'react-native';
4
-
5
- export type VideoNativeProps = Omit<VideoProperties, 'onAudioFocusChanged'> & {
6
- onAudioFocusChanged?: (event: { hasAudioFocus: boolean }) => void;
7
- };
8
-
9
- class FallbackComponent extends ReactComponent<VideoNativeProps & { innerRef: ForwardedRef<View> }> {
10
- render() {
11
- return <View ref={this.props.innerRef} />;
12
- }
13
- }
14
-
15
- const ForwardedComponent = forwardRef<View, VideoNativeProps>((props: VideoNativeProps, ref) => (
16
- <FallbackComponent {...props} innerRef={ref} />
17
- ));
18
-
19
- function getVideoComponent(): ComponentType<VideoNativeProps> {
20
- try {
21
- return require('@granite-js/native/react-native-video')?.default;
22
- } catch {
23
- return ForwardedComponent;
24
- }
25
- }
26
-
27
- export const Component = getVideoComponent();
28
- export const isAvailable = Component !== ForwardedComponent;