@solucx/react-native-solucx-widget 0.1.13 → 0.1.14

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solucx/react-native-solucx-widget",
3
- "version": "0.1.13",
3
+ "version": "0.1.14",
4
4
  "description": "The React Native SDK for Solucx Widget",
5
5
  "main": "src/index",
6
6
  "author": " <> ()",
@@ -14,10 +14,10 @@
14
14
  "README.md"
15
15
  ],
16
16
  "peerDependencies": {
17
- "@react-native-async-storage/async-storage": "^2.2.0",
18
17
  "react": ">=18.0.0",
19
18
  "react-native": ">=0.72.0",
20
- "react-native-webview": "^13.16.0",
21
- "react-native-safe-area-context": "^5.6.1"
19
+ "@react-native-async-storage/async-storage": "^2.2.0",
20
+ "react-native-reanimated": "^3.17.4",
21
+ "react-native-webview": "^13.16.0"
22
22
  }
23
- }
23
+ }
@@ -83,6 +83,7 @@ export const SoluCXWidget: React.FC<SoluCXWidgetProps> = ({
83
83
  source={{ uri }}
84
84
  onLoadEnd={handleWebViewLoad}
85
85
  onMessage={(event) => handleWebViewMessage(event.nativeEvent.data)}
86
+ originWhitelist={['*']}
86
87
  />
87
88
  </ModalWidget>
88
89
  );
@@ -97,6 +98,7 @@ export const SoluCXWidget: React.FC<SoluCXWidgetProps> = ({
97
98
  source={{ uri }}
98
99
  onLoadEnd={handleWebViewLoad}
99
100
  onMessage={(event) => handleWebViewMessage(event.nativeEvent.data)}
101
+ originWhitelist={['*']}
100
102
  />
101
103
  </InlineWidget>
102
104
  );
@@ -110,6 +112,7 @@ export const SoluCXWidget: React.FC<SoluCXWidgetProps> = ({
110
112
  source={{ uri }}
111
113
  onLoadEnd={handleWebViewLoad}
112
114
  onMessage={(event) => handleWebViewMessage(event.nativeEvent.data)}
115
+ originWhitelist={['*']}
113
116
  />
114
117
  </OverlayWidget>
115
118
  );
@@ -1,9 +1,8 @@
1
1
  import React, { useEffect } from 'react';
2
2
  import { View } from 'react-native';
3
- import { styles, getWidgetVisibility } from '../styles/widgetStyles';
3
+ import { styles, getWidgetVisibility, useHeightAnimation } from '../styles/widgetStyles';
4
4
  import { CloseButton } from './CloseButton';
5
- import { Animated } from 'react-native';
6
- import { useHeightAnimation } from '../hooks/useHeightAnimation';
5
+ import Animated from 'react-native-reanimated';
7
6
 
8
7
  interface InlineWidgetProps {
9
8
  visible: boolean;
@@ -12,12 +11,7 @@ interface InlineWidgetProps {
12
11
  onClose?: () => void;
13
12
  }
14
13
 
15
- export const InlineWidget: React.FC<InlineWidgetProps> = ({
16
- visible,
17
- height,
18
- children,
19
- onClose,
20
- }) => {
14
+ export const InlineWidget: React.FC<InlineWidgetProps> = ({ visible, height, children, onClose }) => {
21
15
  const { animatedHeightStyle, updateHeight } = useHeightAnimation(height);
22
16
 
23
17
  useEffect(() => {
@@ -26,10 +20,12 @@ export const InlineWidget: React.FC<InlineWidgetProps> = ({
26
20
 
27
21
  return (
28
22
  <View style={[styles.inlineWrapper, getWidgetVisibility(visible)]}>
29
- <Animated.View
30
- style={[styles.inline, animatedHeightStyle, getWidgetVisibility(visible)]}>
23
+ <Animated.View style={[styles.inline, animatedHeightStyle, getWidgetVisibility(visible)]}>
31
24
  {children}
32
- <CloseButton visible={visible} onPress={onClose || (() => { })} />
25
+ <CloseButton
26
+ visible={visible}
27
+ onPress={onClose || (() => { })}
28
+ />
33
29
  </Animated.View>
34
30
  </View>
35
31
  );
@@ -1,8 +1,8 @@
1
1
  import React, { useState, useEffect } from 'react';
2
- import { Modal, SafeAreaView, View, Animated } from 'react-native';
3
- import { styles, getWidgetVisibility } from '../styles/widgetStyles';
2
+ import { Modal, SafeAreaView, View } from 'react-native';
3
+ import { styles, getWidgetVisibility, useHeightAnimation } from '../styles/widgetStyles';
4
4
  import { CloseButton } from './CloseButton';
5
- import { useHeightAnimation } from '../hooks/useHeightAnimation';
5
+ import Animated from 'react-native-reanimated';
6
6
 
7
7
  interface ModalWidgetProps {
8
8
  visible: boolean;
@@ -11,12 +11,7 @@ interface ModalWidgetProps {
11
11
  onClose?: () => void;
12
12
  }
13
13
 
14
- export const ModalWidget: React.FC<ModalWidgetProps> = ({
15
- visible,
16
- height,
17
- children,
18
- onClose,
19
- }) => {
14
+ export const ModalWidget: React.FC<ModalWidgetProps> = ({ visible, height, children, onClose }) => {
20
15
  const [isWidgetVisible, setIsWidgetVisible] = useState<boolean>(true);
21
16
 
22
17
  const { animatedHeightStyle, updateHeight } = useHeightAnimation(height);
@@ -27,20 +22,9 @@ export const ModalWidget: React.FC<ModalWidgetProps> = ({
27
22
 
28
23
  return (
29
24
  <SafeAreaView>
30
- <Modal
31
- transparent
32
- visible={isWidgetVisible}
33
- animationType="slide"
34
- hardwareAccelerated
35
- >
25
+ <Modal transparent visible={isWidgetVisible} animationType="slide" hardwareAccelerated>
36
26
  <View style={[styles.modalOverlay, getWidgetVisibility(visible)]}>
37
- <Animated.View
38
- style={[
39
- styles.modalContent,
40
- getWidgetVisibility(visible),
41
- animatedHeightStyle,
42
- ]}
43
- >
27
+ <Animated.View style={[styles.modalContent, getWidgetVisibility(visible), animatedHeightStyle]}>
44
28
  {children}
45
29
  <CloseButton
46
30
  visible={visible}
@@ -1,10 +1,10 @@
1
1
  import React, { useState, useEffect } from 'react';
2
- import { View, ViewStyle, Animated } from 'react-native';
2
+ import { View, ViewStyle } from 'react-native';
3
3
  import { initialWindowMetrics } from 'react-native-safe-area-context';
4
- import { getWidgetStyles, getWidgetVisibility } from '../styles/widgetStyles';
4
+ import { getWidgetStyles, getWidgetVisibility, useHeightAnimation } from '../styles/widgetStyles';
5
5
  import { FIXED_Z_INDEX } from '../constants/webViewConstants';
6
6
  import { CloseButton } from './CloseButton';
7
- import { useHeightAnimation } from '../hooks/useHeightAnimation';
7
+ import Animated from 'react-native-reanimated';
8
8
 
9
9
  interface OverlayWidgetProps {
10
10
  visible: boolean;
@@ -23,8 +23,7 @@ export const OverlayWidget: React.FC<OverlayWidgetProps> = ({
23
23
  children,
24
24
  onClose,
25
25
  }) => {
26
- const insets =
27
- initialWindowMetrics?.insets ?? { top: 0, bottom: 0, left: 0, right: 0 };
26
+ const insets = initialWindowMetrics?.insets ?? { top: 0, bottom: 0, left: 0, right: 0 };
28
27
  const [isWidgetVisible, setIsWidgetVisible] = useState<boolean>(true);
29
28
 
30
29
  const { animatedHeightStyle, updateHeight } = useHeightAnimation(height);
@@ -42,8 +41,8 @@ export const OverlayWidget: React.FC<OverlayWidgetProps> = ({
42
41
  width: '100%',
43
42
  height: '100%',
44
43
  zIndex: FIXED_Z_INDEX,
45
- pointerEvents: 'box-none',
46
- };
44
+ pointerEvents: 'box-none'
45
+ }
47
46
 
48
47
  const contentStyle = [
49
48
  getWidgetStyles(position).content,
@@ -56,20 +55,14 @@ export const OverlayWidget: React.FC<OverlayWidgetProps> = ({
56
55
  ...(position === 'bottom' && {
57
56
  bottom: insets.bottom,
58
57
  }),
59
- },
58
+ }
60
59
  ];
61
60
 
62
61
  return (
63
62
  <>
64
63
  {isWidgetVisible && (
65
64
  <View style={[containerStyle, getWidgetVisibility(visible)]}>
66
- <Animated.View
67
- style={[
68
- contentStyle,
69
- animatedHeightStyle,
70
- getWidgetVisibility(visible),
71
- ]}
72
- >
65
+ <Animated.View style={[contentStyle, animatedHeightStyle, getWidgetVisibility(visible)]}>
73
66
  {children}
74
67
  <CloseButton
75
68
  visible={visible}
@@ -1,5 +1,30 @@
1
1
  import { StyleSheet } from 'react-native';
2
2
  import { WidgetType } from '../interfaces';
3
+ import {
4
+ useSharedValue,
5
+ withTiming,
6
+ useAnimatedStyle,
7
+ Easing,
8
+ } from 'react-native-reanimated';
9
+
10
+ export const useHeightAnimation = (height: number) => {
11
+ const animatedHeight = useSharedValue(height);
12
+
13
+ const animatedHeightStyle = useAnimatedStyle(() => {
14
+ return {
15
+ height: animatedHeight.value,
16
+ };
17
+ });
18
+
19
+ const updateHeight = (newHeight: number) => {
20
+ animatedHeight.value = withTiming(newHeight, {
21
+ duration: 300,
22
+ easing: Easing.bezier(0.25, 0.1, 0.25, 1),
23
+ });
24
+ };
25
+
26
+ return { animatedHeightStyle, updateHeight };
27
+ };
3
28
 
4
29
  export const styles = StyleSheet.create({
5
30
  wrapper: {
@@ -1,22 +0,0 @@
1
- // hooks/useHeightAnimation.ts
2
- import { useRef, useCallback } from 'react';
3
- import { Animated } from 'react-native';
4
-
5
- export function useHeightAnimation(initialHeight = 0, duration = 300) {
6
- const height = useRef(new Animated.Value(initialHeight)).current;
7
-
8
- const updateHeight = useCallback(
9
- (toValue: number) => {
10
- Animated.timing(height, {
11
- toValue,
12
- duration,
13
- useNativeDriver: false,
14
- }).start();
15
- },
16
- [height, duration],
17
- );
18
-
19
- const animatedHeightStyle = { height };
20
-
21
- return { animatedHeightStyle, updateHeight, height };
22
- }