rnnovaui 0.9.7 → 0.9.9

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": "rnnovaui",
3
- "version": "0.9.7",
3
+ "version": "0.9.9",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "react-native": "src/index.js",
@@ -12,24 +12,19 @@ export const UIAccordionContent = memo(function UIAccordionContent({
12
12
  testID,
13
13
  }) {
14
14
  const accordion = useUIAccordion();
15
-
16
15
  const item = useUIAccordionItem();
17
16
 
18
17
  const [contentHeight, setContentHeight] = useState(0);
19
18
 
20
- const heightAnimation = useRef(new Animated.Value(item.open ? 1 : 0)).current;
21
-
22
- const opacityAnimation = useRef(
23
- new Animated.Value(item.open ? 1 : 0),
24
- ).current;
19
+ const animation = useRef(new Animated.Value(item.open ? 1 : 0)).current;
25
20
 
26
21
  /*
27
22
  * ------------------------------------------------
28
- * MEASURE REAL CONTENT HEIGHT
23
+ * MEASURE REAL CONTENT
29
24
  * ------------------------------------------------
30
25
  */
31
26
 
32
- const handleLayout = (event) => {
27
+ const handleMeasureLayout = (event) => {
33
28
  const height = Math.ceil(event.nativeEvent.layout.height);
34
29
 
35
30
  if (height > 0 && height !== contentHeight) {
@@ -39,51 +34,36 @@ export const UIAccordionContent = memo(function UIAccordionContent({
39
34
 
40
35
  /*
41
36
  * ------------------------------------------------
42
- * ANIMATION
37
+ * OPEN / CLOSE
43
38
  * ------------------------------------------------
44
39
  */
45
40
 
46
41
  useEffect(() => {
47
- /*
48
- * If content has not been measured yet,
49
- * don't try to animate to an unknown height.
50
- */
51
42
  if (contentHeight <= 0) {
52
43
  return;
53
44
  }
54
45
 
55
46
  if (!accordion.animated) {
56
- heightAnimation.setValue(item.open ? 1 : 0);
57
-
58
- opacityAnimation.setValue(item.open ? 1 : 0);
47
+ animation.setValue(item.open ? 1 : 0);
59
48
 
60
49
  return;
61
50
  }
62
51
 
63
- Animated.parallel([
64
- Animated.timing(heightAnimation, {
65
- toValue: item.open ? 1 : 0,
66
-
67
- duration: accordion.animationDuration,
52
+ Animated.timing(animation, {
53
+ toValue: item.open ? 1 : 0,
68
54
 
69
- useNativeDriver: false,
70
- }),
55
+ duration: accordion.animationDuration,
71
56
 
72
- Animated.timing(opacityAnimation, {
73
- toValue: item.open ? 1 : 0,
57
+ easing: undefined,
74
58
 
75
- duration: Math.min(accordion.animationDuration, 160),
76
-
77
- useNativeDriver: true,
78
- }),
79
- ]).start();
59
+ useNativeDriver: false,
60
+ }).start();
80
61
  }, [
81
62
  item.open,
82
63
  contentHeight,
83
64
  accordion.animated,
84
65
  accordion.animationDuration,
85
- heightAnimation,
86
- opacityAnimation,
66
+ animation,
87
67
  ]);
88
68
 
89
69
  /*
@@ -92,51 +72,94 @@ export const UIAccordionContent = memo(function UIAccordionContent({
92
72
  * ------------------------------------------------
93
73
  */
94
74
 
95
- const animatedHeight = heightAnimation.interpolate({
75
+ const animatedHeight = animation.interpolate({
96
76
  inputRange: [0, 1],
97
77
 
98
78
  outputRange: [0, contentHeight],
79
+
80
+ extrapolate: "clamp",
99
81
  });
100
82
 
101
83
  /*
102
84
  * ------------------------------------------------
103
- * CONTENT
104
- * ------------------------------------------------
85
+ * MEASUREMENT CONTENT
105
86
  *
106
- * The inner content remains mounted all the time.
107
- * Therefore backend content can have any height.
87
+ * This is always rendered.
88
+ *
89
+ * It does NOT participate in normal layout.
90
+ * Therefore it cannot cause accordion shaking.
91
+ * ------------------------------------------------
108
92
  */
109
93
 
110
94
  return (
111
- <Animated.View
112
- testID={testID}
113
- style={[
114
- styles.container,
115
-
116
- {
117
- height: animatedHeight,
118
-
119
- opacity: opacityAnimation,
120
- },
121
-
122
- style,
123
- ]}
124
- >
125
- <View style={[styles.inner, innerStyle]} onLayout={handleLayout}>
126
- {children}
95
+ <View style={styles.root}>
96
+ <View pointerEvents="none" style={styles.measureContainer}>
97
+ <View
98
+ style={[styles.measureContent, innerStyle]}
99
+ onLayout={handleMeasureLayout}
100
+ >
101
+ {children}
102
+ </View>
127
103
  </View>
128
- </Animated.View>
104
+
105
+ <Animated.View
106
+ testID={testID}
107
+ style={[
108
+ styles.animatedContainer,
109
+
110
+ {
111
+ height: animatedHeight,
112
+ },
113
+
114
+ style,
115
+ ]}
116
+ >
117
+ <View style={[styles.visibleContent, innerStyle]}>{children}</View>
118
+ </Animated.View>
119
+ </View>
129
120
  );
130
121
  });
131
122
 
132
123
  const styles = StyleSheet.create({
133
- container: {
124
+ root: {
125
+ width: "100%",
126
+ },
127
+
128
+ /*
129
+ * Hidden measurement layer.
130
+ *
131
+ * It remains available so onLayout can always
132
+ * calculate the real content height.
133
+ */
134
+ measureContainer: {
135
+ position: "absolute",
136
+
137
+ left: 0,
138
+ right: 0,
139
+
140
+ top: 0,
141
+
142
+ opacity: 0,
143
+
144
+ zIndex: -1,
145
+
146
+ pointerEvents: "none",
147
+ },
148
+
149
+ measureContent: {
150
+ width: "100%",
151
+ },
152
+
153
+ /*
154
+ * Visible animated layer.
155
+ */
156
+ animatedContainer: {
134
157
  width: "100%",
135
158
 
136
159
  overflow: "hidden",
137
160
  },
138
161
 
139
- inner: {
162
+ visibleContent: {
140
163
  width: "100%",
141
164
  },
142
165
  });