@fountain-ui/lab 2.0.0-beta.8 → 2.0.0-beta.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.
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = AnimatedY;
7
7
 
8
- var _react = _interopRequireDefault(require("react"));
8
+ var _react = _interopRequireWildcard(require("react"));
9
9
 
10
10
  var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
11
11
 
@@ -13,7 +13,10 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
13
13
 
14
14
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
15
15
 
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
+ const ANIMATION_CONFIG = {
17
+ duration: 150,
18
+ easing: _reactNativeReanimated.Easing.out(_reactNativeReanimated.Easing.exp)
19
+ };
17
20
 
18
21
  function AnimatedY(props) {
19
22
  const {
@@ -26,17 +29,12 @@ function AnimatedY(props) {
26
29
  transform: [{
27
30
  translateY: animatedY.value
28
31
  }]
29
- }));
30
-
31
- _react.default.useEffect(() => {
32
+ }), []);
33
+ (0, _react.useEffect)(() => {
32
34
  if (translateY >= 0) {
33
- animatedY.value = (0, _reactNativeReanimated.withTiming)(translateY, {
34
- duration: 150,
35
- easing: _reactNativeReanimated.Easing.out(_reactNativeReanimated.Easing.exp)
36
- });
35
+ animatedY.value = (0, _reactNativeReanimated.withTiming)(translateY, ANIMATION_CONFIG);
37
36
  }
38
37
  }, [translateY]);
39
-
40
38
  return /*#__PURE__*/_react.default.createElement(_reactNativeReanimated.default.View, {
41
39
  children: children,
42
40
  style: [animatedStyle, style]
@@ -1 +1 @@
1
- {"version":3,"names":["AnimatedY","props","children","translateY","style","animatedY","useSharedValue","animatedStyle","useAnimatedStyle","transform","value","React","useEffect","withTiming","duration","easing","Easing","out","exp"],"sources":["AnimatedY.tsx"],"sourcesContent":["import React from 'react';\nimport Animated, { Easing, useAnimatedStyle, useSharedValue, withTiming } from 'react-native-reanimated';\nimport type AnimatedYProps from './AnimatedYProps';\n\nexport default function AnimatedY(props: AnimatedYProps) {\n const {\n children,\n translateY,\n style,\n } = props;\n\n const animatedY = useSharedValue(translateY);\n const animatedStyle = useAnimatedStyle(() => ({\n transform: [{ translateY: animatedY.value }],\n }));\n\n React.useEffect(() => {\n if (translateY >= 0) {\n animatedY.value = withTiming(translateY, {\n duration: 150,\n easing: Easing.out(Easing.exp),\n });\n }\n }, [translateY]);\n\n return (\n <Animated.View\n children={children}\n style={[\n animatedStyle,\n style,\n ]}\n />\n );\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;;;;;;;AAGe,SAASA,SAAT,CAAmBC,KAAnB,EAA0C;EACrD,MAAM;IACFC,QADE;IAEFC,UAFE;IAGFC;EAHE,IAIFH,KAJJ;EAMA,MAAMI,SAAS,GAAG,IAAAC,qCAAA,EAAeH,UAAf,CAAlB;EACA,MAAMI,aAAa,GAAG,IAAAC,uCAAA,EAAiB,OAAO;IAC1CC,SAAS,EAAE,CAAC;MAAEN,UAAU,EAAEE,SAAS,CAACK;IAAxB,CAAD;EAD+B,CAAP,CAAjB,CAAtB;;EAIAC,cAAA,CAAMC,SAAN,CAAgB,MAAM;IAClB,IAAIT,UAAU,IAAI,CAAlB,EAAqB;MACjBE,SAAS,CAACK,KAAV,GAAkB,IAAAG,iCAAA,EAAWV,UAAX,EAAuB;QACrCW,QAAQ,EAAE,GAD2B;QAErCC,MAAM,EAAEC,6BAAA,CAAOC,GAAP,CAAWD,6BAAA,CAAOE,GAAlB;MAF6B,CAAvB,CAAlB;IAIH;EACJ,CAPD,EAOG,CAACf,UAAD,CAPH;;EASA,oBACI,6BAAC,8BAAD,CAAU,IAAV;IACI,QAAQ,EAAED,QADd;IAEI,KAAK,EAAE,CACHK,aADG,EAEHH,KAFG;EAFX,EADJ;AASH;;AAAA"}
1
+ {"version":3,"names":["ANIMATION_CONFIG","duration","easing","Easing","out","exp","AnimatedY","props","children","translateY","style","animatedY","useSharedValue","animatedStyle","useAnimatedStyle","transform","value","useEffect","withTiming"],"sources":["AnimatedY.tsx"],"sourcesContent":["import React, { useEffect } from 'react';\nimport type { WithTimingConfig } from 'react-native-reanimated';\nimport Animated, { Easing, useAnimatedStyle, useSharedValue, withTiming } from 'react-native-reanimated';\nimport type AnimatedYProps from './AnimatedYProps';\n\nconst ANIMATION_CONFIG: Readonly<WithTimingConfig> = {\n duration: 150,\n easing: Easing.out(Easing.exp),\n};\n\nexport default function AnimatedY(props: AnimatedYProps) {\n const {\n children,\n translateY,\n style,\n } = props;\n\n const animatedY = useSharedValue(translateY);\n const animatedStyle = useAnimatedStyle(() => ({\n transform: [{ translateY: animatedY.value }],\n }), []);\n\n useEffect(() => {\n if (translateY >= 0) {\n animatedY.value = withTiming(translateY, ANIMATION_CONFIG);\n }\n }, [translateY]);\n\n return (\n <Animated.View\n children={children}\n style={[\n animatedStyle,\n style,\n ]}\n />\n );\n};\n"],"mappings":";;;;;;;AAAA;;AAEA;;;;;;AAGA,MAAMA,gBAA4C,GAAG;EACjDC,QAAQ,EAAE,GADuC;EAEjDC,MAAM,EAAEC,6BAAA,CAAOC,GAAP,CAAWD,6BAAA,CAAOE,GAAlB;AAFyC,CAArD;;AAKe,SAASC,SAAT,CAAmBC,KAAnB,EAA0C;EACrD,MAAM;IACFC,QADE;IAEFC,UAFE;IAGFC;EAHE,IAIFH,KAJJ;EAMA,MAAMI,SAAS,GAAG,IAAAC,qCAAA,EAAeH,UAAf,CAAlB;EACA,MAAMI,aAAa,GAAG,IAAAC,uCAAA,EAAiB,OAAO;IAC1CC,SAAS,EAAE,CAAC;MAAEN,UAAU,EAAEE,SAAS,CAACK;IAAxB,CAAD;EAD+B,CAAP,CAAjB,EAElB,EAFkB,CAAtB;EAIA,IAAAC,gBAAA,EAAU,MAAM;IACZ,IAAIR,UAAU,IAAI,CAAlB,EAAqB;MACjBE,SAAS,CAACK,KAAV,GAAkB,IAAAE,iCAAA,EAAWT,UAAX,EAAuBT,gBAAvB,CAAlB;IACH;EACJ,CAJD,EAIG,CAACS,UAAD,CAJH;EAMA,oBACI,6BAAC,8BAAD,CAAU,IAAV;IACI,QAAQ,EAAED,QADd;IAEI,KAAK,EAAE,CACHK,aADG,EAEHH,KAFG;EAFX,EADJ;AASH;;AAAA"}
@@ -48,7 +48,7 @@ function FlipCard(props) {
48
48
  rotateX: `${sharedAngle.value}deg`
49
49
  }]
50
50
  };
51
- });
51
+ }, []);
52
52
  const animatedBackCardStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => {
53
53
  return {
54
54
  zIndex: sharedAngle.value <= Z_INDEX_CHANGE_ANGLE ? 1 : 2,
@@ -58,7 +58,7 @@ function FlipCard(props) {
58
58
  rotateX: `${sharedAngle.value + 180}deg`
59
59
  }]
60
60
  };
61
- });
61
+ }, []);
62
62
  (0, _react.useEffect)(() => {
63
63
  sharedAngle.value = 0;
64
64
  sharedAngle.value = (0, _reactNativeReanimated.withTiming)(180, {
@@ -1 +1 @@
1
- {"version":3,"names":["styles","StyleSheet","create","container","height","width","animatedCard","alignItems","backfaceVisibility","justifyContent","position","PERSPECTIVE","Z_INDEX_CHANGE_ANGLE","FlipCard","props","backCard","frontCard","reanimationKey","style","sharedAngle","useSharedValue","animatedFrontCardStyle","useAnimatedStyle","zIndex","value","transform","perspective","rotateX","animatedBackCardStyle","useEffect","withTiming","duration"],"sources":["FlipCard.tsx"],"sourcesContent":["import React, { useEffect } from 'react';\nimport { StyleSheet, View } from 'react-native';\nimport Animated, { useAnimatedStyle, useSharedValue, withTiming } from 'react-native-reanimated';\nimport type FlipCardProps from './FlipCardProps';\n\nconst styles = StyleSheet.create({\n container: {\n height: 32,\n width: 24,\n },\n animatedCard: {\n alignItems: 'center',\n backfaceVisibility: 'hidden',\n justifyContent: 'center',\n position: 'absolute',\n },\n});\n\nconst PERSPECTIVE = 100;\nconst Z_INDEX_CHANGE_ANGLE = 90;\n\nexport default function FlipCard(props: FlipCardProps) {\n const {\n backCard,\n frontCard,\n reanimationKey,\n style,\n } = props;\n\n const sharedAngle = useSharedValue(0);\n\n const animatedFrontCardStyle = useAnimatedStyle(() => {\n return {\n zIndex: sharedAngle.value < Z_INDEX_CHANGE_ANGLE ? 2 : 1,\n transform: [\n { perspective: PERSPECTIVE },\n { rotateX: `${sharedAngle.value}deg` },\n ],\n };\n });\n\n const animatedBackCardStyle = useAnimatedStyle(() => {\n return {\n zIndex: sharedAngle.value <= Z_INDEX_CHANGE_ANGLE ? 1 : 2,\n transform: [\n { perspective: PERSPECTIVE },\n { rotateX: `${(sharedAngle.value + 180)}deg` },\n ],\n };\n });\n\n useEffect(() => {\n sharedAngle.value = 0;\n sharedAngle.value = withTiming(180, { duration: 500 });\n }, [reanimationKey]);\n\n return (\n <View style={[styles.container, style]}>\n <Animated.View style={[styles.animatedCard, animatedFrontCardStyle]}>\n {frontCard}\n </Animated.View>\n\n <Animated.View style={[styles.animatedCard, animatedBackCardStyle]}>\n {backCard}\n </Animated.View>\n </View>\n );\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;;;;;AAGA,MAAMA,MAAM,GAAGC,uBAAA,CAAWC,MAAX,CAAkB;EAC7BC,SAAS,EAAE;IACPC,MAAM,EAAE,EADD;IAEPC,KAAK,EAAE;EAFA,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BACI,6BAAC,iBAAD;IAAM,KAAK,EAAE,CAACjB,MAAM,CAACG,SAAR,EAAmBe,KAAnB;EAAb,gBACI,6BAAC,8BAAD,CAAU,IAAV;IAAe,KAAK,EAAE,CAAClB,MAAM,CAACM,YAAR,EAAsBe,sBAAtB;EAAtB,GACKL,SADL,CADJ,eAKI,6BAAC,8BAAD,CAAU,IAAV;IAAe,KAAK,EAAE,CAAChB,MAAM,CAACM,YAAR,EAAsBsB,qBAAtB;EAAtB,GACKb,QADL,CALJ,CADJ;AAWH;;AAAA"}
1
+ {"version":3,"names":["styles","StyleSheet","create","container","height","width","animatedCard","alignItems","backfaceVisibility","justifyContent","position","PERSPECTIVE","Z_INDEX_CHANGE_ANGLE","FlipCard","props","backCard","frontCard","reanimationKey","style","sharedAngle","useSharedValue","animatedFrontCardStyle","useAnimatedStyle","zIndex","value","transform","perspective","rotateX","animatedBackCardStyle","useEffect","withTiming","duration"],"sources":["FlipCard.tsx"],"sourcesContent":["import React, { useEffect } from 'react';\nimport { StyleSheet, View } from 'react-native';\nimport Animated, { useAnimatedStyle, useSharedValue, withTiming } from 'react-native-reanimated';\nimport type FlipCardProps from './FlipCardProps';\n\nconst styles = StyleSheet.create({\n container: {\n height: 32,\n width: 24,\n },\n animatedCard: {\n alignItems: 'center',\n backfaceVisibility: 'hidden',\n justifyContent: 'center',\n position: 'absolute',\n },\n});\n\nconst PERSPECTIVE = 100;\nconst Z_INDEX_CHANGE_ANGLE = 90;\n\nexport default function FlipCard(props: FlipCardProps) {\n const {\n backCard,\n frontCard,\n reanimationKey,\n style,\n } = props;\n\n const sharedAngle = useSharedValue(0);\n\n const animatedFrontCardStyle = useAnimatedStyle(() => {\n return {\n zIndex: sharedAngle.value < Z_INDEX_CHANGE_ANGLE ? 2 : 1,\n transform: [\n { perspective: PERSPECTIVE },\n { rotateX: `${sharedAngle.value}deg` },\n ],\n };\n }, []);\n\n const animatedBackCardStyle = useAnimatedStyle(() => {\n return {\n zIndex: sharedAngle.value <= Z_INDEX_CHANGE_ANGLE ? 1 : 2,\n transform: [\n { perspective: PERSPECTIVE },\n { rotateX: `${(sharedAngle.value + 180)}deg` },\n ],\n };\n }, []);\n\n useEffect(() => {\n sharedAngle.value = 0;\n sharedAngle.value = withTiming(180, { duration: 500 });\n }, [reanimationKey]);\n\n return (\n <View style={[styles.container, style]}>\n <Animated.View style={[styles.animatedCard, animatedFrontCardStyle]}>\n {frontCard}\n </Animated.View>\n\n <Animated.View style={[styles.animatedCard, animatedBackCardStyle]}>\n {backCard}\n </Animated.View>\n </View>\n );\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;;;;;AAGA,MAAMA,MAAM,GAAGC,uBAAA,CAAWC,MAAX,CAAkB;EAC7BC,SAAS,EAAE;IACPC,MAAM,EAAE,EADD;IAEPC,KAAK,EAAE;EAFA,CADkB;EAK7BC,YAAY,EAAE;IACVC,UAAU,EAAE,QADF;IAEVC,kBAAkB,EAAE,QAFV;IAGVC,cAAc,EAAE,QAHN;IAIVC,QAAQ,EAAE;EAJA;AALe,CAAlB,CAAf;;AAaA,MAAMC,WAAW,GAAG,GAApB;AACA,MAAMC,oBAAoB,GAAG,EAA7B;;AAEe,SAASC,QAAT,CAAkBC,KAAlB,EAAwC;EACnD,MAAM;IACFC,QADE;IAEFC,SAFE;IAGFC,cAHE;IAIFC;EAJE,IAKFJ,KALJ;EAOA,MAAMK,WAAW,GAAG,IAAAC,qCAAA,EAAe,CAAf,CAApB;EAEA,MAAMC,sBAAsB,GAAG,IAAAC,uCAAA,EAAiB,MAAM;IAClD,OAAO;MACHC,MAAM,EAAEJ,WAAW,CAACK,KAAZ,GAAoBZ,oBAApB,GAA2C,CAA3C,GAA+C,CADpD;MAEHa,SAAS,EAAE,CACP;QAAEC,WAAW,EAAEf;MAAf,CADO,EAEP;QAAEgB,OAAO,EAAG,GAAER,WAAW,CAACK,KAAM;MAAhC,CAFO;IAFR,CAAP;EAOH,CAR8B,EAQ5B,EAR4B,CAA/B;EAUA,MAAMI,qBAAqB,GAAG,IAAAN,uCAAA,EAAiB,MAAM;IACjD,OAAO;MACHC,MAAM,EAAEJ,WAAW,CAACK,KAAZ,IAAqBZ,oBAArB,GAA4C,CAA5C,GAAgD,CADrD;MAEHa,SAAS,EAAE,CACP;QAAEC,WAAW,EAAEf;MAAf,CADO,EAEP;QAAEgB,OAAO,EAAG,GAAGR,WAAW,CAACK,KAAZ,GAAoB,GAAK;MAAxC,CAFO;IAFR,CAAP;EAOH,CAR6B,EAQ3B,EAR2B,CAA9B;EAUA,IAAAK,gBAAA,EAAU,MAAM;IACZV,WAAW,CAACK,KAAZ,GAAoB,CAApB;IACAL,WAAW,CAACK,KAAZ,GAAoB,IAAAM,iCAAA,EAAW,GAAX,EAAgB;MAAEC,QAAQ,EAAE;IAAZ,CAAhB,CAApB;EACH,CAHD,EAGG,CAACd,cAAD,CAHH;EAKA,oBACI,6BAAC,iBAAD;IAAM,KAAK,EAAE,CAACjB,MAAM,CAACG,SAAR,EAAmBe,KAAnB;EAAb,gBACI,6BAAC,8BAAD,CAAU,IAAV;IAAe,KAAK,EAAE,CAAClB,MAAM,CAACM,YAAR,EAAsBe,sBAAtB;EAAtB,GACKL,SADL,CADJ,eAKI,6BAAC,8BAAD,CAAU,IAAV;IAAe,KAAK,EAAE,CAAChB,MAAM,CAACM,YAAR,EAAsBsB,qBAAtB;EAAtB,GACKb,QADL,CALJ,CADJ;AAWH;;AAAA"}
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = useUnstableCollapsibleAppBar;
7
7
 
8
- var _react = _interopRequireWildcard(require("react"));
8
+ var _react = require("react");
9
9
 
10
10
  var _reactNative = require("react-native");
11
11
 
@@ -21,10 +21,6 @@ var _useHeight = _interopRequireDefault(require("./useHeight"));
21
21
 
22
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
23
 
24
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
25
-
26
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
27
-
28
24
  const defaultOptions = {
29
25
  shouldTranslateYReset: false
30
26
  };
@@ -50,7 +46,7 @@ function useUnstableCollapsibleAppBar() {
50
46
  const [appBarHeight, onAppBarLayout] = (0, _useHeight.default)();
51
47
  const appBarMaxHeight = useLargerValueOfLastTwoValues(appBarHeight);
52
48
  const [collapsibleToolbarHeight, onCollapsibleToolbarLayout] = (0, _useHeight.default)();
53
- const maxTranslateY = (0, _reactNativeReanimated.useDerivedValue)(() => -collapsibleToolbarHeight);
49
+ const maxTranslateY = (0, _reactNativeReanimated.useDerivedValue)(() => -collapsibleToolbarHeight, [collapsibleToolbarHeight]);
54
50
  const translateY = (0, _reactNativeReanimated.useSharedValue)(0);
55
51
  const lastTranslateY = (0, _reactNativeReanimated.useSharedValue)(0);
56
52
  const lastOffsetY = (0, _reactNativeReanimated.useSharedValue)(0);
@@ -59,29 +55,27 @@ function useUnstableCollapsibleAppBar() {
59
55
  const vectorY = (0, _reactNativeReanimated.useSharedValue)(0);
60
56
  const elevationStyle = (0, _useElevationStyle.default)(4);
61
57
  const animatedStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => {
58
+ const transform = [{
59
+ translateY: translateY.value
60
+ }];
61
+
62
62
  if (_reactNative.Platform.OS === 'web') {
63
63
  return {
64
- transform: [{
65
- translateY: translateY.value
66
- }],
64
+ transform,
67
65
  boxShadow: overlapped.value ? elevationStyle === null || elevationStyle === void 0 ? void 0 : elevationStyle.boxShadow : 0
68
66
  };
69
67
  }
70
68
 
71
69
  if (_reactNative.Platform.OS === 'android') {
72
70
  return {
73
- transform: [{
74
- translateY: translateY.value
75
- }],
71
+ transform,
76
72
  elevation: overlapped.value ? elevationStyle === null || elevationStyle === void 0 ? void 0 : elevationStyle.elevation : 0
77
73
  };
78
74
  }
79
75
 
80
76
  if (_reactNative.Platform.OS === 'ios') {
81
77
  return {
82
- transform: [{
83
- translateY: translateY.value
84
- }],
78
+ transform,
85
79
  shadowColor: elevationStyle === null || elevationStyle === void 0 ? void 0 : elevationStyle.shadowColor,
86
80
  shadowOffset: elevationStyle === null || elevationStyle === void 0 ? void 0 : elevationStyle.shadowOffset,
87
81
  shadowRadius: elevationStyle === null || elevationStyle === void 0 ? void 0 : elevationStyle.shadowRadius,
@@ -90,11 +84,13 @@ function useUnstableCollapsibleAppBar() {
90
84
  }
91
85
 
92
86
  return {};
93
- });
94
-
95
- const indexRef = _react.default.useRef(0);
96
-
97
- const offsetsRef = _react.default.useRef([]);
87
+ }, [
88
+ /**
89
+ * FIXME: Consider add `elevationStyle` to dependencies.
90
+ */
91
+ ]);
92
+ const indexRef = (0, _react.useRef)(0);
93
+ const offsetsRef = (0, _react.useRef)([]);
98
94
 
99
95
  const onScrollViewChanged = nextIndex => {
100
96
  const prevIndex = indexRef.current;
@@ -185,7 +181,7 @@ function useUnstableCollapsibleAppBar() {
185
181
  duration: ANIMATION_DURATION_MILLIS
186
182
  });
187
183
  }
188
- });
184
+ }, []);
189
185
  const hasCollapsible = collapsibleToolbarHeight > 0;
190
186
  const appBarStyle = [animatedStyle, {
191
187
  paddingTop: safeAreaInsets.top
@@ -1 +1 @@
1
- {"version":3,"names":["defaultOptions","shouldTranslateYReset","ANIMATION_DURATION_MILLIS","SUPPORTS_DRAG_DETECTION","Platform","OS","useLargerValueOfLastTwoValues","value","refLatestTwoValues","useRef","current","shift","push","Math","max","useUnstableCollapsibleAppBar","userOptions","styles","useAppbarStyles","safeAreaInsets","useSafeAreaInsets","appBarHeight","onAppBarLayout","useHeight","appBarMaxHeight","collapsibleToolbarHeight","onCollapsibleToolbarLayout","maxTranslateY","useDerivedValue","translateY","useSharedValue","lastTranslateY","lastOffsetY","prevOffsetY","overlapped","vectorY","elevationStyle","useElevationStyle","animatedStyle","useAnimatedStyle","transform","boxShadow","elevation","shadowColor","shadowOffset","shadowRadius","shadowOpacity","indexRef","React","offsetsRef","onScrollViewChanged","nextIndex","prevIndex","withTiming","duration","savedOffsetY","scrollHandler","useAnimatedScrollHandler","onBeginDrag","onMomentumBegin","onScroll","event","offsetY","contentOffset","y","ty","maxTy","deltaY","dy","min","onEndDrag","onMomentumEnd","threshold","nextTranslateY","hasCollapsible","appBarStyle","paddingTop","top","floating","undefined","scrollContentInsets"],"sources":["useUnstableCollapsibleAppBar.ts"],"sourcesContent":["import React, { useRef } from 'react';\nimport { Falsy, Platform, RegisteredStyle, ScrollViewProps, ViewProps, ViewStyle } from 'react-native';\nimport type { SharedValue } from 'react-native-reanimated';\nimport {\n useAnimatedScrollHandler,\n useAnimatedStyle,\n useDerivedValue,\n useSharedValue,\n withTiming,\n} from 'react-native-reanimated';\nimport { useSafeAreaInsets } from 'react-native-safe-area-context';\nimport useAppbarStyles from './useAppbarStyles';\nimport useElevationStyle from './useElevationStyle';\nimport useHeight from './useHeight';\n\ntype WebOnlyStyle = { boxShadow: any };\n\ntype ViewStyleProp = Array<ViewStyle | RegisteredStyle<ViewStyle> | WebOnlyStyle | Falsy>;\n\ntype OnScroll = ScrollViewProps['onScroll'];\n\ntype OnLayoutCallback = ViewProps['onLayout'];\n\nexport interface ContentInsets {\n top?: number;\n bottom?: number;\n left?: number;\n right?: number;\n}\n\nexport interface Options {\n shouldTranslateYReset?: boolean;\n}\n\nexport interface CollapsibleAppBar {\n appBarStyle: ViewStyleProp;\n vectorY: SharedValue<number>;\n onAppBarLayout: OnLayoutCallback;\n onCollapsibleToolbarLayout: OnLayoutCallback;\n onScroll: OnScroll;\n onScrollViewChanged: (index: number) => void;\n scrollContentInsets: ContentInsets;\n}\n\nconst defaultOptions: Required<Options> = {\n shouldTranslateYReset: false,\n};\n\nconst ANIMATION_DURATION_MILLIS = 100;\n\nconst SUPPORTS_DRAG_DETECTION = Platform.OS !== 'web';\n\n\nfunction useLargerValueOfLastTwoValues(value: number) {\n const refLatestTwoValues = useRef([0, 0]);\n\n refLatestTwoValues.current.shift();\n refLatestTwoValues.current.push(value);\n\n return Math.max(...refLatestTwoValues.current);\n}\n\n\nexport default function useUnstableCollapsibleAppBar(userOptions: Options = defaultOptions): CollapsibleAppBar {\n const { shouldTranslateYReset }: Required<Options> = {\n ...defaultOptions,\n ...userOptions,\n };\n\n const styles = useAppbarStyles();\n\n const safeAreaInsets = useSafeAreaInsets();\n\n const [appBarHeight, onAppBarLayout] = useHeight();\n const appBarMaxHeight = useLargerValueOfLastTwoValues(appBarHeight);\n const [collapsibleToolbarHeight, onCollapsibleToolbarLayout] = useHeight();\n\n const maxTranslateY = useDerivedValue(() => -collapsibleToolbarHeight);\n\n const translateY = useSharedValue<number>(0);\n const lastTranslateY = useSharedValue<number>(0);\n const lastOffsetY = useSharedValue<number>(0);\n const prevOffsetY = useSharedValue<number>(0);\n const overlapped = useSharedValue<boolean>(false);\n const vectorY = useSharedValue<number>(0);\n\n const elevationStyle = useElevationStyle(4);\n const animatedStyle = useAnimatedStyle(() => {\n if (Platform.OS === 'web') {\n return {\n transform: [{ translateY: translateY.value }],\n boxShadow: overlapped.value ? elevationStyle?.boxShadow : 0,\n };\n }\n if (Platform.OS === 'android') {\n return {\n transform: [{ translateY: translateY.value }],\n elevation: overlapped.value ? elevationStyle?.elevation : 0,\n };\n }\n if (Platform.OS === 'ios') {\n return {\n transform: [{ translateY: translateY.value }],\n shadowColor: elevationStyle?.shadowColor,\n shadowOffset: elevationStyle?.shadowOffset,\n shadowRadius: elevationStyle?.shadowRadius,\n shadowOpacity: overlapped.value ? elevationStyle?.shadowOpacity : 0,\n };\n }\n return {};\n });\n\n const indexRef = React.useRef<number>(0);\n const offsetsRef = React.useRef<Array<number>>([]);\n\n const onScrollViewChanged = (nextIndex: number) => {\n const prevIndex = indexRef.current;\n if (prevIndex === nextIndex) {\n if (shouldTranslateYReset) {\n translateY.value = withTiming(0, {\n duration: ANIMATION_DURATION_MILLIS,\n });\n\n vectorY.value = 0;\n offsetsRef.current = [];\n overlapped.value = false;\n }\n\n return;\n }\n\n offsetsRef.current[prevIndex] = lastOffsetY.value;\n\n const savedOffsetY = offsetsRef.current[nextIndex] ?? 0;\n lastOffsetY.value = savedOffsetY;\n\n indexRef.current = nextIndex;\n\n // Determine whether to overlap every time index is changed.\n overlapped.value = savedOffsetY > 0;\n\n // If next ScrollView's offset is too short, expand app bar.\n if (translateY.value < 0 && savedOffsetY < appBarHeight) {\n translateY.value = withTiming(0, {\n duration: ANIMATION_DURATION_MILLIS,\n });\n\n vectorY.value = 0;\n }\n };\n\n const scrollHandler = useAnimatedScrollHandler({\n onBeginDrag: () => {\n lastTranslateY.value = translateY.value;\n },\n onMomentumBegin: () => {\n lastTranslateY.value = translateY.value;\n },\n onScroll: (event) => {\n const offsetY = event.contentOffset.y;\n\n const ty = translateY.value;\n const maxTy = maxTranslateY.value;\n\n const deltaY = offsetY - prevOffsetY.value;\n vectorY.value = (vectorY.value * deltaY >= 0 && offsetY > 0) ? vectorY.value + deltaY : deltaY;\n prevOffsetY.value = offsetY;\n\n if (SUPPORTS_DRAG_DETECTION) {\n const dy = offsetY - lastOffsetY.value;\n\n translateY.value = offsetY <= 0 ? 0 : Math.min(Math.max(lastTranslateY.value - dy, maxTy), 0);\n\n overlapped.value = offsetY + translateY.value > 0;\n } else {\n if (offsetY > -maxTy) {\n if (ty === 0) {\n translateY.value = withTiming(Math.min(Math.max(-offsetY, maxTy), 0), {\n duration: ANIMATION_DURATION_MILLIS,\n });\n }\n } else {\n if (ty === maxTy) {\n translateY.value = withTiming(0, {\n duration: ANIMATION_DURATION_MILLIS,\n });\n }\n }\n\n overlapped.value = offsetY > 0;\n\n lastOffsetY.value = offsetY;\n }\n },\n onEndDrag: (event) => {\n lastOffsetY.value = event.contentOffset.y;\n },\n onMomentumEnd: (event) => {\n const offsetY = event.contentOffset.y;\n\n lastOffsetY.value = offsetY;\n\n const ty = translateY.value;\n const maxTy = maxTranslateY.value;\n\n // If toolbar is already positioned on edge, do nothing.\n if (ty <= maxTy || ty >= 0) {\n return;\n }\n\n const threshold = maxTy * 0.5;\n\n const nextTranslateY = (ty > threshold || offsetY < appBarHeight) ? 0 : maxTy;\n\n overlapped.value = offsetY + nextTranslateY > 0;\n\n translateY.value = withTiming(nextTranslateY, {\n duration: ANIMATION_DURATION_MILLIS,\n });\n },\n });\n\n const hasCollapsible = collapsibleToolbarHeight > 0;\n\n const appBarStyle = [\n animatedStyle,\n { paddingTop: safeAreaInsets.top },\n hasCollapsible ? styles.floating : undefined,\n ];\n\n return {\n appBarStyle,\n vectorY,\n onAppBarLayout,\n onCollapsibleToolbarLayout,\n onScroll: scrollHandler,\n onScrollViewChanged,\n scrollContentInsets: { top: hasCollapsible ? appBarMaxHeight : 0 },\n };\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;AAEA;;AAOA;;AACA;;AACA;;AACA;;;;;;;;AA+BA,MAAMA,cAAiC,GAAG;EACtCC,qBAAqB,EAAE;AADe,CAA1C;AAIA,MAAMC,yBAAyB,GAAG,GAAlC;AAEA,MAAMC,uBAAuB,GAAGC,qBAAA,CAASC,EAAT,KAAgB,KAAhD;;AAGA,SAASC,6BAAT,CAAuCC,KAAvC,EAAsD;EAClD,MAAMC,kBAAkB,GAAG,IAAAC,aAAA,EAAO,CAAC,C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B;EAMA,OAAO;IACHJ,WADG;IAEHxC,OAFG;IAGHb,cAHG;IAIHI,0BAJG;IAKHkC,QAAQ,EAAEJ,aALP;IAMHN,mBANG;IAOH8B,mBAAmB,EAAE;MAAEH,GAAG,EAAEH,cAAc,GAAGlD,eAAH,GAAqB;IAA1C;EAPlB,CAAP;AASH;;AAAA"}
1
+ {"version":3,"names":["defaultOptions","shouldTranslateYReset","ANIMATION_DURATION_MILLIS","SUPPORTS_DRAG_DETECTION","Platform","OS","useLargerValueOfLastTwoValues","value","refLatestTwoValues","useRef","current","shift","push","Math","max","useUnstableCollapsibleAppBar","userOptions","styles","useAppbarStyles","safeAreaInsets","useSafeAreaInsets","appBarHeight","onAppBarLayout","useHeight","appBarMaxHeight","collapsibleToolbarHeight","onCollapsibleToolbarLayout","maxTranslateY","useDerivedValue","translateY","useSharedValue","lastTranslateY","lastOffsetY","prevOffsetY","overlapped","vectorY","elevationStyle","useElevationStyle","animatedStyle","useAnimatedStyle","transform","boxShadow","elevation","shadowColor","shadowOffset","shadowRadius","shadowOpacity","indexRef","offsetsRef","onScrollViewChanged","nextIndex","prevIndex","withTiming","duration","savedOffsetY","scrollHandler","useAnimatedScrollHandler","onBeginDrag","onMomentumBegin","onScroll","event","offsetY","contentOffset","y","ty","maxTy","deltaY","dy","min","onEndDrag","onMomentumEnd","threshold","nextTranslateY","hasCollapsible","appBarStyle","paddingTop","top","floating","undefined","scrollContentInsets"],"sources":["useUnstableCollapsibleAppBar.ts"],"sourcesContent":["import { useRef } from 'react';\nimport { Falsy, Platform, RegisteredStyle, ScrollViewProps, ViewProps, ViewStyle } from 'react-native';\nimport type { SharedValue } from 'react-native-reanimated';\nimport {\n useAnimatedScrollHandler,\n useAnimatedStyle,\n useDerivedValue,\n useSharedValue,\n withTiming,\n} from 'react-native-reanimated';\nimport { useSafeAreaInsets } from 'react-native-safe-area-context';\nimport useAppbarStyles from './useAppbarStyles';\nimport useElevationStyle from './useElevationStyle';\nimport useHeight from './useHeight';\n\ntype WebOnlyStyle = { boxShadow: any };\n\ntype ViewStyleProp = Array<ViewStyle | RegisteredStyle<ViewStyle> | WebOnlyStyle | Falsy>;\n\ntype OnScroll = ScrollViewProps['onScroll'];\n\ntype OnLayoutCallback = ViewProps['onLayout'];\n\nexport interface ContentInsets {\n top?: number;\n bottom?: number;\n left?: number;\n right?: number;\n}\n\nexport interface Options {\n shouldTranslateYReset?: boolean;\n}\n\nexport interface CollapsibleAppBar {\n appBarStyle: ViewStyleProp;\n vectorY: SharedValue<number>;\n onAppBarLayout: OnLayoutCallback;\n onCollapsibleToolbarLayout: OnLayoutCallback;\n onScroll: OnScroll;\n onScrollViewChanged: (index: number) => void;\n scrollContentInsets: ContentInsets;\n}\n\nconst defaultOptions: Required<Options> = {\n shouldTranslateYReset: false,\n};\n\nconst ANIMATION_DURATION_MILLIS = 100;\n\nconst SUPPORTS_DRAG_DETECTION = Platform.OS !== 'web';\n\nfunction useLargerValueOfLastTwoValues(value: number) {\n const refLatestTwoValues = useRef([0, 0]);\n\n refLatestTwoValues.current.shift();\n refLatestTwoValues.current.push(value);\n\n return Math.max(...refLatestTwoValues.current);\n}\n\nexport default function useUnstableCollapsibleAppBar(userOptions: Options = defaultOptions): CollapsibleAppBar {\n const { shouldTranslateYReset }: Required<Options> = {\n ...defaultOptions,\n ...userOptions,\n };\n\n const styles = useAppbarStyles();\n\n const safeAreaInsets = useSafeAreaInsets();\n\n const [appBarHeight, onAppBarLayout] = useHeight();\n const appBarMaxHeight = useLargerValueOfLastTwoValues(appBarHeight);\n const [collapsibleToolbarHeight, onCollapsibleToolbarLayout] = useHeight();\n\n const maxTranslateY = useDerivedValue(() => -collapsibleToolbarHeight, [collapsibleToolbarHeight]);\n\n const translateY = useSharedValue<number>(0);\n const lastTranslateY = useSharedValue<number>(0);\n const lastOffsetY = useSharedValue<number>(0);\n const prevOffsetY = useSharedValue<number>(0);\n const overlapped = useSharedValue<boolean>(false);\n const vectorY = useSharedValue<number>(0);\n\n const elevationStyle = useElevationStyle(4);\n const animatedStyle = useAnimatedStyle(() => {\n const transform = [{ translateY: translateY.value }];\n\n if (Platform.OS === 'web') {\n return {\n transform,\n boxShadow: overlapped.value ? elevationStyle?.boxShadow : 0,\n };\n }\n if (Platform.OS === 'android') {\n return {\n transform,\n elevation: overlapped.value ? elevationStyle?.elevation : 0,\n };\n }\n if (Platform.OS === 'ios') {\n return {\n transform,\n shadowColor: elevationStyle?.shadowColor,\n shadowOffset: elevationStyle?.shadowOffset,\n shadowRadius: elevationStyle?.shadowRadius,\n shadowOpacity: overlapped.value ? elevationStyle?.shadowOpacity : 0,\n };\n }\n return {};\n }, [\n /**\n * FIXME: Consider add `elevationStyle` to dependencies.\n */\n ]);\n\n const indexRef = useRef<number>(0);\n const offsetsRef = useRef<Array<number>>([]);\n\n const onScrollViewChanged = (nextIndex: number) => {\n const prevIndex = indexRef.current;\n if (prevIndex === nextIndex) {\n if (shouldTranslateYReset) {\n translateY.value = withTiming(0, {\n duration: ANIMATION_DURATION_MILLIS,\n });\n\n vectorY.value = 0;\n offsetsRef.current = [];\n overlapped.value = false;\n }\n\n return;\n }\n\n offsetsRef.current[prevIndex] = lastOffsetY.value;\n\n const savedOffsetY = offsetsRef.current[nextIndex] ?? 0;\n lastOffsetY.value = savedOffsetY;\n\n indexRef.current = nextIndex;\n\n // Determine whether to overlap every time index is changed.\n overlapped.value = savedOffsetY > 0;\n\n // If next ScrollView's offset is too short, expand app bar.\n if (translateY.value < 0 && savedOffsetY < appBarHeight) {\n translateY.value = withTiming(0, {\n duration: ANIMATION_DURATION_MILLIS,\n });\n\n vectorY.value = 0;\n }\n };\n\n const scrollHandler = useAnimatedScrollHandler({\n onBeginDrag: () => {\n lastTranslateY.value = translateY.value;\n },\n onMomentumBegin: () => {\n lastTranslateY.value = translateY.value;\n },\n onScroll: (event) => {\n const offsetY = event.contentOffset.y;\n\n const ty = translateY.value;\n const maxTy = maxTranslateY.value;\n\n const deltaY = offsetY - prevOffsetY.value;\n vectorY.value = (vectorY.value * deltaY >= 0 && offsetY > 0) ? vectorY.value + deltaY : deltaY;\n prevOffsetY.value = offsetY;\n\n if (SUPPORTS_DRAG_DETECTION) {\n const dy = offsetY - lastOffsetY.value;\n\n translateY.value = offsetY <= 0 ? 0 : Math.min(Math.max(lastTranslateY.value - dy, maxTy), 0);\n\n overlapped.value = offsetY + translateY.value > 0;\n } else {\n if (offsetY > -maxTy) {\n if (ty === 0) {\n translateY.value = withTiming(Math.min(Math.max(-offsetY, maxTy), 0), {\n duration: ANIMATION_DURATION_MILLIS,\n });\n }\n } else {\n if (ty === maxTy) {\n translateY.value = withTiming(0, {\n duration: ANIMATION_DURATION_MILLIS,\n });\n }\n }\n\n overlapped.value = offsetY > 0;\n\n lastOffsetY.value = offsetY;\n }\n },\n onEndDrag: (event) => {\n lastOffsetY.value = event.contentOffset.y;\n },\n onMomentumEnd: (event) => {\n const offsetY = event.contentOffset.y;\n\n lastOffsetY.value = offsetY;\n\n const ty = translateY.value;\n const maxTy = maxTranslateY.value;\n\n // If toolbar is already positioned on edge, do nothing.\n if (ty <= maxTy || ty >= 0) {\n return;\n }\n\n const threshold = maxTy * 0.5;\n\n const nextTranslateY = (ty > threshold || offsetY < appBarHeight) ? 0 : maxTy;\n\n overlapped.value = offsetY + nextTranslateY > 0;\n\n translateY.value = withTiming(nextTranslateY, {\n duration: ANIMATION_DURATION_MILLIS,\n });\n },\n }, []);\n\n const hasCollapsible = collapsibleToolbarHeight > 0;\n\n const appBarStyle = [\n animatedStyle,\n { paddingTop: safeAreaInsets.top },\n hasCollapsible ? styles.floating : undefined,\n ];\n\n return {\n appBarStyle,\n vectorY,\n onAppBarLayout,\n onCollapsibleToolbarLayout,\n onScroll: scrollHandler,\n onScrollViewChanged,\n scrollContentInsets: { top: hasCollapsible ? appBarMaxHeight : 0 },\n };\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;AAEA;;AAOA;;AACA;;AACA;;AACA;;;;AA+BA,MAAMA,cAAiC,GAAG;EACtCC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B,GAAG,CAAlD;EAEA,MAAMiD,WAAW,GAAG,CAChBpC,aADgB,EAEhB;IAAEqC,UAAU,EAAExD,cAAc,CAACyD;EAA7B,CAFgB,EAGhBH,cAAc,GAAGxD,MAAM,CAAC4D,QAAV,GAAqBC,SAHnB,CAApB;EAMA,OAAO;IACHJ,WADG;IAEHvC,OAFG;IAGHb,cAHG;IAIHI,0BAJG;IAKHiC,QAAQ,EAAEJ,aALP;IAMHN,mBANG;IAOH8B,mBAAmB,EAAE;MAAEH,GAAG,EAAEH,cAAc,GAAGjD,eAAH,GAAqB;IAA1C;EAPlB,CAAP;AASH;;AAAA"}
@@ -17,10 +17,10 @@ function useAnimatedDisplayStyle(vectorY) {
17
17
  } else if (vy < threshold) {
18
18
  display.value = 'flex';
19
19
  }
20
- });
20
+ }, [threshold]);
21
21
  return (0, _reactNativeReanimated.useAnimatedStyle)(() => ({
22
22
  display: display.value
23
- }));
23
+ }), []);
24
24
  }
25
25
 
26
26
  ;
@@ -1 +1 @@
1
- {"version":3,"names":["useAnimatedDisplayStyle","vectorY","threshold","defaultDisplay","display","useSharedValue","useAnimatedReaction","value","vy","useAnimatedStyle"],"sources":["useUnstableToggleDisplayStyle.ts"],"sourcesContent":["import type { SharedValue } from 'react-native-reanimated';\nimport { useAnimatedReaction, useAnimatedStyle, useSharedValue } from 'react-native-reanimated';\n\nexport default function useAnimatedDisplayStyle(\n vectorY: SharedValue<number>,\n threshold: number = 200,\n defaultDisplay: 'flex' | 'none' = 'flex',\n) {\n const display = useSharedValue(defaultDisplay);\n\n useAnimatedReaction(\n () => vectorY.value,\n (vy) => {\n if (vy >= threshold) {\n display.value = 'none';\n } else if (vy < threshold) {\n display.value = 'flex';\n }\n },\n );\n\n return useAnimatedStyle(() => ({\n display: display.value,\n }));\n};\n"],"mappings":";;;;;;;AACA;;AAEe,SAASA,uBAAT,CACXC,OADW,EAIb;EAAA,IAFEC,SAEF,uEAFsB,GAEtB;EAAA,IADEC,cACF,uEADoC,MACpC;EACE,MAAMC,OAAO,GAAG,IAAAC,qCAAA,EAAeF,cAAf,CAAhB;EAEA,IAAAG,0CAAA,EACI,MAAML,OAAO,CAACM,KADlB,EAEKC,EAAD,IAAQ;IACJ,IAAIA,EAAE,IAAIN,SAAV,EAAqB;MACjBE,OAAO,CAACG,KAAR,GAAgB,MAAhB;IACH,CAFD,MAEO,IAAIC,EAAE,GAAGN,SAAT,EAAoB;MACvBE,OAAO,CAACG,KAAR,GAAgB,MAAhB;IACH;EACJ,CARL;EAWA,OAAO,IAAAE,uCAAA,EAAiB,OAAO;IAC3BL,OAAO,EAAEA,OAAO,CAACG;EADU,CAAP,CAAjB,CAAP;AAGH;;AAAA"}
1
+ {"version":3,"names":["useAnimatedDisplayStyle","vectorY","threshold","defaultDisplay","display","useSharedValue","useAnimatedReaction","value","vy","useAnimatedStyle"],"sources":["useUnstableToggleDisplayStyle.ts"],"sourcesContent":["import type { SharedValue } from 'react-native-reanimated';\nimport { useAnimatedReaction, useAnimatedStyle, useSharedValue } from 'react-native-reanimated';\n\nexport default function useAnimatedDisplayStyle(\n vectorY: SharedValue<number>,\n threshold: number = 200,\n defaultDisplay: 'flex' | 'none' = 'flex',\n) {\n const display = useSharedValue(defaultDisplay);\n\n useAnimatedReaction(\n () => vectorY.value,\n (vy) => {\n if (vy >= threshold) {\n display.value = 'none';\n } else if (vy < threshold) {\n display.value = 'flex';\n }\n },\n [threshold],\n );\n\n return useAnimatedStyle(() => ({\n display: display.value,\n }), []);\n};\n"],"mappings":";;;;;;;AACA;;AAEe,SAASA,uBAAT,CACXC,OADW,EAIb;EAAA,IAFEC,SAEF,uEAFsB,GAEtB;EAAA,IADEC,cACF,uEADoC,MACpC;EACE,MAAMC,OAAO,GAAG,IAAAC,qCAAA,EAAeF,cAAf,CAAhB;EAEA,IAAAG,0CAAA,EACI,MAAML,OAAO,CAACM,KADlB,EAEKC,EAAD,IAAQ;IACJ,IAAIA,EAAE,IAAIN,SAAV,EAAqB;MACjBE,OAAO,CAACG,KAAR,GAAgB,MAAhB;IACH,CAFD,MAEO,IAAIC,EAAE,GAAGN,SAAT,EAAoB;MACvBE,OAAO,CAACG,KAAR,GAAgB,MAAhB;IACH;EACJ,CARL,EASI,CAACL,SAAD,CATJ;EAYA,OAAO,IAAAO,uCAAA,EAAiB,OAAO;IAC3BL,OAAO,EAAEA,OAAO,CAACG;EADU,CAAP,CAAjB,EAEH,EAFG,CAAP;AAGH;;AAAA"}
@@ -1,5 +1,9 @@
1
- import React from 'react';
1
+ import React, { useEffect } from 'react';
2
2
  import Animated, { Easing, useAnimatedStyle, useSharedValue, withTiming } from 'react-native-reanimated';
3
+ const ANIMATION_CONFIG = {
4
+ duration: 150,
5
+ easing: Easing.out(Easing.exp)
6
+ };
3
7
  export default function AnimatedY(props) {
4
8
  const {
5
9
  children,
@@ -11,13 +15,10 @@ export default function AnimatedY(props) {
11
15
  transform: [{
12
16
  translateY: animatedY.value
13
17
  }]
14
- }));
15
- React.useEffect(() => {
18
+ }), []);
19
+ useEffect(() => {
16
20
  if (translateY >= 0) {
17
- animatedY.value = withTiming(translateY, {
18
- duration: 150,
19
- easing: Easing.out(Easing.exp)
20
- });
21
+ animatedY.value = withTiming(translateY, ANIMATION_CONFIG);
21
22
  }
22
23
  }, [translateY]);
23
24
  return /*#__PURE__*/React.createElement(Animated.View, {
@@ -1 +1 @@
1
- {"version":3,"names":["React","Animated","Easing","useAnimatedStyle","useSharedValue","withTiming","AnimatedY","props","children","translateY","style","animatedY","animatedStyle","transform","value","useEffect","duration","easing","out","exp"],"sources":["AnimatedY.tsx"],"sourcesContent":["import React from 'react';\nimport Animated, { Easing, useAnimatedStyle, useSharedValue, withTiming } from 'react-native-reanimated';\nimport type AnimatedYProps from './AnimatedYProps';\n\nexport default function AnimatedY(props: AnimatedYProps) {\n const {\n children,\n translateY,\n style,\n } = props;\n\n const animatedY = useSharedValue(translateY);\n const animatedStyle = useAnimatedStyle(() => ({\n transform: [{ translateY: animatedY.value }],\n }));\n\n React.useEffect(() => {\n if (translateY >= 0) {\n animatedY.value = withTiming(translateY, {\n duration: 150,\n easing: Easing.out(Easing.exp),\n });\n }\n }, [translateY]);\n\n return (\n <Animated.View\n children={children}\n style={[\n animatedStyle,\n style,\n ]}\n />\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,OAAOC,QAAP,IAAmBC,MAAnB,EAA2BC,gBAA3B,EAA6CC,cAA7C,EAA6DC,UAA7D,QAA+E,yBAA/E;AAGA,eAAe,SAASC,SAAT,CAAmBC,KAAnB,EAA0C;EACrD,MAAM;IACFC,QADE;IAEFC,UAFE;IAGFC;EAHE,IAIFH,KAJJ;EAMA,MAAMI,SAAS,GAAGP,cAAc,CAACK,UAAD,CAAhC;EACA,MAAMG,aAAa,GAAGT,gBAAgB,CAAC,OAAO;IAC1CU,SAAS,EAAE,CAAC;MAAEJ,UAAU,EAAEE,SAAS,CAACG;IAAxB,CAAD;EAD+B,CAAP,CAAD,CAAtC;EAIAd,KAAK,CAACe,SAAN,CAAgB,MAAM;IAClB,IAAIN,UAAU,IAAI,CAAlB,EAAqB;MACjBE,SAAS,CAACG,KAAV,GAAkBT,UAAU,CAACI,UAAD,EAAa;QACrCO,QAAQ,EAAE,GAD2B;QAErCC,MAAM,EAAEf,MAAM,CAACgB,GAAP,CAAWhB,MAAM,CAACiB,GAAlB;MAF6B,CAAb,CAA5B;IAIH;EACJ,CAPD,EAOG,CAACV,UAAD,CAPH;EASA,oBACI,oBAAC,QAAD,CAAU,IAAV;IACI,QAAQ,EAAED,QADd;IAEI,KAAK,EAAE,CACHI,aADG,EAEHF,KAFG;EAFX,EADJ;AASH;AAAA"}
1
+ {"version":3,"names":["React","useEffect","Animated","Easing","useAnimatedStyle","useSharedValue","withTiming","ANIMATION_CONFIG","duration","easing","out","exp","AnimatedY","props","children","translateY","style","animatedY","animatedStyle","transform","value"],"sources":["AnimatedY.tsx"],"sourcesContent":["import React, { useEffect } from 'react';\nimport type { WithTimingConfig } from 'react-native-reanimated';\nimport Animated, { Easing, useAnimatedStyle, useSharedValue, withTiming } from 'react-native-reanimated';\nimport type AnimatedYProps from './AnimatedYProps';\n\nconst ANIMATION_CONFIG: Readonly<WithTimingConfig> = {\n duration: 150,\n easing: Easing.out(Easing.exp),\n};\n\nexport default function AnimatedY(props: AnimatedYProps) {\n const {\n children,\n translateY,\n style,\n } = props;\n\n const animatedY = useSharedValue(translateY);\n const animatedStyle = useAnimatedStyle(() => ({\n transform: [{ translateY: animatedY.value }],\n }), []);\n\n useEffect(() => {\n if (translateY >= 0) {\n animatedY.value = withTiming(translateY, ANIMATION_CONFIG);\n }\n }, [translateY]);\n\n return (\n <Animated.View\n children={children}\n style={[\n animatedStyle,\n style,\n ]}\n />\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,SAAhB,QAAiC,OAAjC;AAEA,OAAOC,QAAP,IAAmBC,MAAnB,EAA2BC,gBAA3B,EAA6CC,cAA7C,EAA6DC,UAA7D,QAA+E,yBAA/E;AAGA,MAAMC,gBAA4C,GAAG;EACjDC,QAAQ,EAAE,GADuC;EAEjDC,MAAM,EAAEN,MAAM,CAACO,GAAP,CAAWP,MAAM,CAACQ,GAAlB;AAFyC,CAArD;AAKA,eAAe,SAASC,SAAT,CAAmBC,KAAnB,EAA0C;EACrD,MAAM;IACFC,QADE;IAEFC,UAFE;IAGFC;EAHE,IAIFH,KAJJ;EAMA,MAAMI,SAAS,GAAGZ,cAAc,CAACU,UAAD,CAAhC;EACA,MAAMG,aAAa,GAAGd,gBAAgB,CAAC,OAAO;IAC1Ce,SAAS,EAAE,CAAC;MAAEJ,UAAU,EAAEE,SAAS,CAACG;IAAxB,CAAD;EAD+B,CAAP,CAAD,EAElC,EAFkC,CAAtC;EAIAnB,SAAS,CAAC,MAAM;IACZ,IAAIc,UAAU,IAAI,CAAlB,EAAqB;MACjBE,SAAS,CAACG,KAAV,GAAkBd,UAAU,CAACS,UAAD,EAAaR,gBAAb,CAA5B;IACH;EACJ,CAJQ,EAIN,CAACQ,UAAD,CAJM,CAAT;EAMA,oBACI,oBAAC,QAAD,CAAU,IAAV;IACI,QAAQ,EAAED,QADd;IAEI,KAAK,EAAE,CACHI,aADG,EAEHF,KAFG;EAFX,EADJ;AASH;AAAA"}
@@ -32,7 +32,7 @@ export default function FlipCard(props) {
32
32
  rotateX: `${sharedAngle.value}deg`
33
33
  }]
34
34
  };
35
- });
35
+ }, []);
36
36
  const animatedBackCardStyle = useAnimatedStyle(() => {
37
37
  return {
38
38
  zIndex: sharedAngle.value <= Z_INDEX_CHANGE_ANGLE ? 1 : 2,
@@ -42,7 +42,7 @@ export default function FlipCard(props) {
42
42
  rotateX: `${sharedAngle.value + 180}deg`
43
43
  }]
44
44
  };
45
- });
45
+ }, []);
46
46
  useEffect(() => {
47
47
  sharedAngle.value = 0;
48
48
  sharedAngle.value = withTiming(180, {
@@ -1 +1 @@
1
- {"version":3,"names":["React","useEffect","StyleSheet","View","Animated","useAnimatedStyle","useSharedValue","withTiming","styles","create","container","height","width","animatedCard","alignItems","backfaceVisibility","justifyContent","position","PERSPECTIVE","Z_INDEX_CHANGE_ANGLE","FlipCard","props","backCard","frontCard","reanimationKey","style","sharedAngle","animatedFrontCardStyle","zIndex","value","transform","perspective","rotateX","animatedBackCardStyle","duration"],"sources":["FlipCard.tsx"],"sourcesContent":["import React, { useEffect } from 'react';\nimport { StyleSheet, View } from 'react-native';\nimport Animated, { useAnimatedStyle, useSharedValue, withTiming } from 'react-native-reanimated';\nimport type FlipCardProps from './FlipCardProps';\n\nconst styles = StyleSheet.create({\n container: {\n height: 32,\n width: 24,\n },\n animatedCard: {\n alignItems: 'center',\n backfaceVisibility: 'hidden',\n justifyContent: 'center',\n position: 'absolute',\n },\n});\n\nconst PERSPECTIVE = 100;\nconst Z_INDEX_CHANGE_ANGLE = 90;\n\nexport default function FlipCard(props: FlipCardProps) {\n const {\n backCard,\n frontCard,\n reanimationKey,\n style,\n } = props;\n\n const sharedAngle = useSharedValue(0);\n\n const animatedFrontCardStyle = useAnimatedStyle(() => {\n return {\n zIndex: sharedAngle.value < Z_INDEX_CHANGE_ANGLE ? 2 : 1,\n transform: [\n { perspective: PERSPECTIVE },\n { rotateX: `${sharedAngle.value}deg` },\n ],\n };\n });\n\n const animatedBackCardStyle = useAnimatedStyle(() => {\n return {\n zIndex: sharedAngle.value <= Z_INDEX_CHANGE_ANGLE ? 1 : 2,\n transform: [\n { perspective: PERSPECTIVE },\n { rotateX: `${(sharedAngle.value + 180)}deg` },\n ],\n };\n });\n\n useEffect(() => {\n sharedAngle.value = 0;\n sharedAngle.value = withTiming(180, { duration: 500 });\n }, [reanimationKey]);\n\n return (\n <View style={[styles.container, style]}>\n <Animated.View style={[styles.animatedCard, animatedFrontCardStyle]}>\n {frontCard}\n </Animated.View>\n\n <Animated.View style={[styles.animatedCard, animatedBackCardStyle]}>\n {backCard}\n </Animated.View>\n </View>\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,SAAhB,QAAiC,OAAjC;AACA,SAASC,UAAT,EAAqBC,IAArB,QAAiC,cAAjC;AACA,OAAOC,QAAP,IAAmBC,gBAAnB,EAAqCC,cAArC,EAAqDC,UAArD,QAAuE,yBAAvE;AAGA,MAAMC,MAAM,GAAGN,UAAU,CAACO,MAAX,CAAkB;EAC7BC,SAAS,EAAE;IACPC,MAAM,EAAE,EADD;IAEPC,KAAK,EAAE;EAFA,CADkB;EAK7BC,YAAY,EAAE;IACVC,UAAU,EAAE,QADF;IAEVC,kBAAkB,EAAE,QAFV;IAGVC,cAAc,EAAE,QAHN;IAIVC,QAAQ,EAAE;EAJA;AALe,CAAlB,CAAf;AAaA,MAAMC,WAAW,GAAG,GAApB;AACA,MAAMC,oBAAoB,GAAG,EAA7B;AAEA,eAAe,SAASC,QAAT,CAAkBC,KAAlB,EAAwC;EACnD,MAAM;IACFC,QADE;IAEFC,SAFE;IAGFC,cAHE;IAIFC;EAJE,IAKFJ,KALJ;EAOA,MAAMK,WAAW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","Animated","useAnimatedStyle","useSharedValue","withTiming","styles","create","container","height","width","animatedCard","alignItems","backfaceVisibility","justifyContent","position","PERSPECTIVE","Z_INDEX_CHANGE_ANGLE","FlipCard","props","backCard","frontCard","reanimationKey","style","sharedAngle","animatedFrontCardStyle","zIndex","value","transform","perspective","rotateX","animatedBackCardStyle","duration"],"sources":["FlipCard.tsx"],"sourcesContent":["import React, { useEffect } from 'react';\nimport { StyleSheet, View } from 'react-native';\nimport Animated, { useAnimatedStyle, useSharedValue, withTiming } from 'react-native-reanimated';\nimport type FlipCardProps from './FlipCardProps';\n\nconst styles = StyleSheet.create({\n container: {\n height: 32,\n width: 24,\n },\n animatedCard: {\n alignItems: 'center',\n backfaceVisibility: 'hidden',\n justifyContent: 'center',\n position: 'absolute',\n },\n});\n\nconst PERSPECTIVE = 100;\nconst Z_INDEX_CHANGE_ANGLE = 90;\n\nexport default function FlipCard(props: FlipCardProps) {\n const {\n backCard,\n frontCard,\n reanimationKey,\n style,\n } = props;\n\n const sharedAngle = useSharedValue(0);\n\n const animatedFrontCardStyle = useAnimatedStyle(() => {\n return {\n zIndex: sharedAngle.value < Z_INDEX_CHANGE_ANGLE ? 2 : 1,\n transform: [\n { perspective: PERSPECTIVE },\n { rotateX: `${sharedAngle.value}deg` },\n ],\n };\n }, []);\n\n const animatedBackCardStyle = useAnimatedStyle(() => {\n return {\n zIndex: sharedAngle.value <= Z_INDEX_CHANGE_ANGLE ? 1 : 2,\n transform: [\n { perspective: PERSPECTIVE },\n { rotateX: `${(sharedAngle.value + 180)}deg` },\n ],\n };\n }, []);\n\n useEffect(() => {\n sharedAngle.value = 0;\n sharedAngle.value = withTiming(180, { duration: 500 });\n }, [reanimationKey]);\n\n return (\n <View style={[styles.container, style]}>\n <Animated.View style={[styles.animatedCard, animatedFrontCardStyle]}>\n {frontCard}\n </Animated.View>\n\n <Animated.View style={[styles.animatedCard, animatedBackCardStyle]}>\n {backCard}\n </Animated.View>\n </View>\n );\n};\n"],"mappings":"AA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W,CAACG,KAAZ,GAAoB,GAAK;MAAxC,CAFO;IAFR,CAAP;EAOH,CAR6C,EAQ3C,EAR2C,CAA9C;EAUA5B,SAAS,CAAC,MAAM;IACZyB,WAAW,CAACG,KAAZ,GAAoB,CAApB;IACAH,WAAW,CAACG,KAAZ,GAAoBtB,UAAU,CAAC,GAAD,EAAM;MAAE2B,QAAQ,EAAE;IAAZ,CAAN,CAA9B;EACH,CAHQ,EAGN,CAACV,cAAD,CAHM,CAAT;EAKA,oBACI,oBAAC,IAAD;IAAM,KAAK,EAAE,CAAChB,MAAM,CAACE,SAAR,EAAmBe,KAAnB;EAAb,gBACI,oBAAC,QAAD,CAAU,IAAV;IAAe,KAAK,EAAE,CAACjB,MAAM,CAACK,YAAR,EAAsBc,sBAAtB;EAAtB,GACKJ,SADL,CADJ,eAKI,oBAAC,QAAD,CAAU,IAAV;IAAe,KAAK,EAAE,CAACf,MAAM,CAACK,YAAR,EAAsBoB,qBAAtB;EAAtB,GACKX,QADL,CALJ,CADJ;AAWH;AAAA"}
@@ -1,4 +1,4 @@
1
- import React, { useRef } from 'react';
1
+ import { useRef } from 'react';
2
2
  import { Platform } from 'react-native';
3
3
  import { useAnimatedScrollHandler, useAnimatedStyle, useDerivedValue, useSharedValue, withTiming } from 'react-native-reanimated';
4
4
  import { useSafeAreaInsets } from 'react-native-safe-area-context';
@@ -30,7 +30,7 @@ export default function useUnstableCollapsibleAppBar() {
30
30
  const [appBarHeight, onAppBarLayout] = useHeight();
31
31
  const appBarMaxHeight = useLargerValueOfLastTwoValues(appBarHeight);
32
32
  const [collapsibleToolbarHeight, onCollapsibleToolbarLayout] = useHeight();
33
- const maxTranslateY = useDerivedValue(() => -collapsibleToolbarHeight);
33
+ const maxTranslateY = useDerivedValue(() => -collapsibleToolbarHeight, [collapsibleToolbarHeight]);
34
34
  const translateY = useSharedValue(0);
35
35
  const lastTranslateY = useSharedValue(0);
36
36
  const lastOffsetY = useSharedValue(0);
@@ -39,29 +39,27 @@ export default function useUnstableCollapsibleAppBar() {
39
39
  const vectorY = useSharedValue(0);
40
40
  const elevationStyle = useElevationStyle(4);
41
41
  const animatedStyle = useAnimatedStyle(() => {
42
+ const transform = [{
43
+ translateY: translateY.value
44
+ }];
45
+
42
46
  if (Platform.OS === 'web') {
43
47
  return {
44
- transform: [{
45
- translateY: translateY.value
46
- }],
48
+ transform,
47
49
  boxShadow: overlapped.value ? elevationStyle === null || elevationStyle === void 0 ? void 0 : elevationStyle.boxShadow : 0
48
50
  };
49
51
  }
50
52
 
51
53
  if (Platform.OS === 'android') {
52
54
  return {
53
- transform: [{
54
- translateY: translateY.value
55
- }],
55
+ transform,
56
56
  elevation: overlapped.value ? elevationStyle === null || elevationStyle === void 0 ? void 0 : elevationStyle.elevation : 0
57
57
  };
58
58
  }
59
59
 
60
60
  if (Platform.OS === 'ios') {
61
61
  return {
62
- transform: [{
63
- translateY: translateY.value
64
- }],
62
+ transform,
65
63
  shadowColor: elevationStyle === null || elevationStyle === void 0 ? void 0 : elevationStyle.shadowColor,
66
64
  shadowOffset: elevationStyle === null || elevationStyle === void 0 ? void 0 : elevationStyle.shadowOffset,
67
65
  shadowRadius: elevationStyle === null || elevationStyle === void 0 ? void 0 : elevationStyle.shadowRadius,
@@ -70,9 +68,13 @@ export default function useUnstableCollapsibleAppBar() {
70
68
  }
71
69
 
72
70
  return {};
73
- });
74
- const indexRef = React.useRef(0);
75
- const offsetsRef = React.useRef([]);
71
+ }, [
72
+ /**
73
+ * FIXME: Consider add `elevationStyle` to dependencies.
74
+ */
75
+ ]);
76
+ const indexRef = useRef(0);
77
+ const offsetsRef = useRef([]);
76
78
 
77
79
  const onScrollViewChanged = nextIndex => {
78
80
  const prevIndex = indexRef.current;
@@ -163,7 +165,7 @@ export default function useUnstableCollapsibleAppBar() {
163
165
  duration: ANIMATION_DURATION_MILLIS
164
166
  });
165
167
  }
166
- });
168
+ }, []);
167
169
  const hasCollapsible = collapsibleToolbarHeight > 0;
168
170
  const appBarStyle = [animatedStyle, {
169
171
  paddingTop: safeAreaInsets.top
@@ -1 +1 @@
1
- {"version":3,"names":["React","useRef","Platform","useAnimatedScrollHandler","useAnimatedStyle","useDerivedValue","useSharedValue","withTiming","useSafeAreaInsets","useAppbarStyles","useElevationStyle","useHeight","defaultOptions","shouldTranslateYReset","ANIMATION_DURATION_MILLIS","SUPPORTS_DRAG_DETECTION","OS","useLargerValueOfLastTwoValues","value","refLatestTwoValues","current","shift","push","Math","max","useUnstableCollapsibleAppBar","userOptions","styles","safeAreaInsets","appBarHeight","onAppBarLayout","appBarMaxHeight","collapsibleToolbarHeight","onCollapsibleToolbarLayout","maxTranslateY","translateY","lastTranslateY","lastOffsetY","prevOffsetY","overlapped","vectorY","elevationStyle","animatedStyle","transform","boxShadow","elevation","shadowColor","shadowOffset","shadowRadius","shadowOpacity","indexRef","offsetsRef","onScrollViewChanged","nextIndex","prevIndex","duration","savedOffsetY","scrollHandler","onBeginDrag","onMomentumBegin","onScroll","event","offsetY","contentOffset","y","ty","maxTy","deltaY","dy","min","onEndDrag","onMomentumEnd","threshold","nextTranslateY","hasCollapsible","appBarStyle","paddingTop","top","floating","undefined","scrollContentInsets"],"sources":["useUnstableCollapsibleAppBar.ts"],"sourcesContent":["import React, { useRef } from 'react';\nimport { Falsy, Platform, RegisteredStyle, ScrollViewProps, ViewProps, ViewStyle } from 'react-native';\nimport type { SharedValue } from 'react-native-reanimated';\nimport {\n useAnimatedScrollHandler,\n useAnimatedStyle,\n useDerivedValue,\n useSharedValue,\n withTiming,\n} from 'react-native-reanimated';\nimport { useSafeAreaInsets } from 'react-native-safe-area-context';\nimport useAppbarStyles from './useAppbarStyles';\nimport useElevationStyle from './useElevationStyle';\nimport useHeight from './useHeight';\n\ntype WebOnlyStyle = { boxShadow: any };\n\ntype ViewStyleProp = Array<ViewStyle | RegisteredStyle<ViewStyle> | WebOnlyStyle | Falsy>;\n\ntype OnScroll = ScrollViewProps['onScroll'];\n\ntype OnLayoutCallback = ViewProps['onLayout'];\n\nexport interface ContentInsets {\n top?: number;\n bottom?: number;\n left?: number;\n right?: number;\n}\n\nexport interface Options {\n shouldTranslateYReset?: boolean;\n}\n\nexport interface CollapsibleAppBar {\n appBarStyle: ViewStyleProp;\n vectorY: SharedValue<number>;\n onAppBarLayout: OnLayoutCallback;\n onCollapsibleToolbarLayout: OnLayoutCallback;\n onScroll: OnScroll;\n onScrollViewChanged: (index: number) => void;\n scrollContentInsets: ContentInsets;\n}\n\nconst defaultOptions: Required<Options> = {\n shouldTranslateYReset: false,\n};\n\nconst ANIMATION_DURATION_MILLIS = 100;\n\nconst SUPPORTS_DRAG_DETECTION = Platform.OS !== 'web';\n\n\nfunction useLargerValueOfLastTwoValues(value: number) {\n const refLatestTwoValues = useRef([0, 0]);\n\n refLatestTwoValues.current.shift();\n refLatestTwoValues.current.push(value);\n\n return Math.max(...refLatestTwoValues.current);\n}\n\n\nexport default function useUnstableCollapsibleAppBar(userOptions: Options = defaultOptions): CollapsibleAppBar {\n const { shouldTranslateYReset }: Required<Options> = {\n ...defaultOptions,\n ...userOptions,\n };\n\n const styles = useAppbarStyles();\n\n const safeAreaInsets = useSafeAreaInsets();\n\n const [appBarHeight, onAppBarLayout] = useHeight();\n const appBarMaxHeight = useLargerValueOfLastTwoValues(appBarHeight);\n const [collapsibleToolbarHeight, onCollapsibleToolbarLayout] = useHeight();\n\n const maxTranslateY = useDerivedValue(() => -collapsibleToolbarHeight);\n\n const translateY = useSharedValue<number>(0);\n const lastTranslateY = useSharedValue<number>(0);\n const lastOffsetY = useSharedValue<number>(0);\n const prevOffsetY = useSharedValue<number>(0);\n const overlapped = useSharedValue<boolean>(false);\n const vectorY = useSharedValue<number>(0);\n\n const elevationStyle = useElevationStyle(4);\n const animatedStyle = useAnimatedStyle(() => {\n if (Platform.OS === 'web') {\n return {\n transform: [{ translateY: translateY.value }],\n boxShadow: overlapped.value ? elevationStyle?.boxShadow : 0,\n };\n }\n if (Platform.OS === 'android') {\n return {\n transform: [{ translateY: translateY.value }],\n elevation: overlapped.value ? elevationStyle?.elevation : 0,\n };\n }\n if (Platform.OS === 'ios') {\n return {\n transform: [{ translateY: translateY.value }],\n shadowColor: elevationStyle?.shadowColor,\n shadowOffset: elevationStyle?.shadowOffset,\n shadowRadius: elevationStyle?.shadowRadius,\n shadowOpacity: overlapped.value ? elevationStyle?.shadowOpacity : 0,\n };\n }\n return {};\n });\n\n const indexRef = React.useRef<number>(0);\n const offsetsRef = React.useRef<Array<number>>([]);\n\n const onScrollViewChanged = (nextIndex: number) => {\n const prevIndex = indexRef.current;\n if (prevIndex === nextIndex) {\n if (shouldTranslateYReset) {\n translateY.value = withTiming(0, {\n duration: ANIMATION_DURATION_MILLIS,\n });\n\n vectorY.value = 0;\n offsetsRef.current = [];\n overlapped.value = false;\n }\n\n return;\n }\n\n offsetsRef.current[prevIndex] = lastOffsetY.value;\n\n const savedOffsetY = offsetsRef.current[nextIndex] ?? 0;\n lastOffsetY.value = savedOffsetY;\n\n indexRef.current = nextIndex;\n\n // Determine whether to overlap every time index is changed.\n overlapped.value = savedOffsetY > 0;\n\n // If next ScrollView's offset is too short, expand app bar.\n if (translateY.value < 0 && savedOffsetY < appBarHeight) {\n translateY.value = withTiming(0, {\n duration: ANIMATION_DURATION_MILLIS,\n });\n\n vectorY.value = 0;\n }\n };\n\n const scrollHandler = useAnimatedScrollHandler({\n onBeginDrag: () => {\n lastTranslateY.value = translateY.value;\n },\n onMomentumBegin: () => {\n lastTranslateY.value = translateY.value;\n },\n onScroll: (event) => {\n const offsetY = event.contentOffset.y;\n\n const ty = translateY.value;\n const maxTy = maxTranslateY.value;\n\n const deltaY = offsetY - prevOffsetY.value;\n vectorY.value = (vectorY.value * deltaY >= 0 && offsetY > 0) ? vectorY.value + deltaY : deltaY;\n prevOffsetY.value = offsetY;\n\n if (SUPPORTS_DRAG_DETECTION) {\n const dy = offsetY - lastOffsetY.value;\n\n translateY.value = offsetY <= 0 ? 0 : Math.min(Math.max(lastTranslateY.value - dy, maxTy), 0);\n\n overlapped.value = offsetY + translateY.value > 0;\n } else {\n if (offsetY > -maxTy) {\n if (ty === 0) {\n translateY.value = withTiming(Math.min(Math.max(-offsetY, maxTy), 0), {\n duration: ANIMATION_DURATION_MILLIS,\n });\n }\n } else {\n if (ty === maxTy) {\n translateY.value = withTiming(0, {\n duration: ANIMATION_DURATION_MILLIS,\n });\n }\n }\n\n overlapped.value = offsetY > 0;\n\n lastOffsetY.value = offsetY;\n }\n },\n onEndDrag: (event) => {\n lastOffsetY.value = event.contentOffset.y;\n },\n onMomentumEnd: (event) => {\n const offsetY = event.contentOffset.y;\n\n lastOffsetY.value = offsetY;\n\n const ty = translateY.value;\n const maxTy = maxTranslateY.value;\n\n // If toolbar is already positioned on edge, do nothing.\n if (ty <= maxTy || ty >= 0) {\n return;\n }\n\n const threshold = maxTy * 0.5;\n\n const nextTranslateY = (ty > threshold || offsetY < appBarHeight) ? 0 : maxTy;\n\n overlapped.value = offsetY + nextTranslateY > 0;\n\n translateY.value = withTiming(nextTranslateY, {\n duration: ANIMATION_DURATION_MILLIS,\n });\n },\n });\n\n const hasCollapsible = collapsibleToolbarHeight > 0;\n\n const appBarStyle = [\n animatedStyle,\n { paddingTop: safeAreaInsets.top },\n hasCollapsible ? styles.floating : undefined,\n ];\n\n return {\n appBarStyle,\n vectorY,\n onAppBarLayout,\n onCollapsibleToolbarLayout,\n onScroll: scrollHandler,\n onScrollViewChanged,\n scrollContentInsets: { top: hasCollapsible ? appBarMaxHeight : 0 },\n };\n};\n"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,MAAhB,QAA8B,OAA9B;AACA,SAAgBC,QAAhB,QAAwF,cAAxF;AAEA,SACIC,wBADJ,EAEIC,gBAFJ,EAGIC,eAHJ,EAIIC,cAJJ,EAKIC,UALJ,QAMO,yBANP;AAOA,SAASC,iBAAT,QAAkC,gCAAlC;AACA,OAAOC,eAAP,MAA4B,mBAA5B;AACA,OAAOC,iBAAP,MAA8B,qBAA9B;AACA,OAAOC,S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AAW,GAAG,CAChBjC,aADgB,EAEhB;IAAEkC,UAAU,EAAEhD,cAAc,CAACiD;EAA7B,CAFgB,EAGhBH,cAAc,GAAG/C,MAAM,CAACmD,QAAV,GAAqBC,SAHnB,CAApB;EAMA,OAAO;IACHJ,WADG;IAEHnC,OAFG;IAGHV,cAHG;IAIHG,0BAJG;IAKH2B,QAAQ,EAAEH,aALP;IAMHL,mBANG;IAOH4B,mBAAmB,EAAE;MAAEH,GAAG,EAAEH,cAAc,GAAG3C,eAAH,GAAqB;IAA1C;EAPlB,CAAP;AASH;AAAA"}
1
+ {"version":3,"names":["useRef","Platform","useAnimatedScrollHandler","useAnimatedStyle","useDerivedValue","useSharedValue","withTiming","useSafeAreaInsets","useAppbarStyles","useElevationStyle","useHeight","defaultOptions","shouldTranslateYReset","ANIMATION_DURATION_MILLIS","SUPPORTS_DRAG_DETECTION","OS","useLargerValueOfLastTwoValues","value","refLatestTwoValues","current","shift","push","Math","max","useUnstableCollapsibleAppBar","userOptions","styles","safeAreaInsets","appBarHeight","onAppBarLayout","appBarMaxHeight","collapsibleToolbarHeight","onCollapsibleToolbarLayout","maxTranslateY","translateY","lastTranslateY","lastOffsetY","prevOffsetY","overlapped","vectorY","elevationStyle","animatedStyle","transform","boxShadow","elevation","shadowColor","shadowOffset","shadowRadius","shadowOpacity","indexRef","offsetsRef","onScrollViewChanged","nextIndex","prevIndex","duration","savedOffsetY","scrollHandler","onBeginDrag","onMomentumBegin","onScroll","event","offsetY","contentOffset","y","ty","maxTy","deltaY","dy","min","onEndDrag","onMomentumEnd","threshold","nextTranslateY","hasCollapsible","appBarStyle","paddingTop","top","floating","undefined","scrollContentInsets"],"sources":["useUnstableCollapsibleAppBar.ts"],"sourcesContent":["import { useRef } from 'react';\nimport { Falsy, Platform, RegisteredStyle, ScrollViewProps, ViewProps, ViewStyle } from 'react-native';\nimport type { SharedValue } from 'react-native-reanimated';\nimport {\n useAnimatedScrollHandler,\n useAnimatedStyle,\n useDerivedValue,\n useSharedValue,\n withTiming,\n} from 'react-native-reanimated';\nimport { useSafeAreaInsets } from 'react-native-safe-area-context';\nimport useAppbarStyles from './useAppbarStyles';\nimport useElevationStyle from './useElevationStyle';\nimport useHeight from './useHeight';\n\ntype WebOnlyStyle = { boxShadow: any };\n\ntype ViewStyleProp = Array<ViewStyle | RegisteredStyle<ViewStyle> | WebOnlyStyle | Falsy>;\n\ntype OnScroll = ScrollViewProps['onScroll'];\n\ntype OnLayoutCallback = ViewProps['onLayout'];\n\nexport interface ContentInsets {\n top?: number;\n bottom?: number;\n left?: number;\n right?: number;\n}\n\nexport interface Options {\n shouldTranslateYReset?: boolean;\n}\n\nexport interface CollapsibleAppBar {\n appBarStyle: ViewStyleProp;\n vectorY: SharedValue<number>;\n onAppBarLayout: OnLayoutCallback;\n onCollapsibleToolbarLayout: OnLayoutCallback;\n onScroll: OnScroll;\n onScrollViewChanged: (index: number) => void;\n scrollContentInsets: ContentInsets;\n}\n\nconst defaultOptions: Required<Options> = {\n shouldTranslateYReset: false,\n};\n\nconst ANIMATION_DURATION_MILLIS = 100;\n\nconst SUPPORTS_DRAG_DETECTION = Platform.OS !== 'web';\n\nfunction useLargerValueOfLastTwoValues(value: number) {\n const refLatestTwoValues = useRef([0, 0]);\n\n refLatestTwoValues.current.shift();\n refLatestTwoValues.current.push(value);\n\n return Math.max(...refLatestTwoValues.current);\n}\n\nexport default function useUnstableCollapsibleAppBar(userOptions: Options = defaultOptions): CollapsibleAppBar {\n const { shouldTranslateYReset }: Required<Options> = {\n ...defaultOptions,\n ...userOptions,\n };\n\n const styles = useAppbarStyles();\n\n const safeAreaInsets = useSafeAreaInsets();\n\n const [appBarHeight, onAppBarLayout] = useHeight();\n const appBarMaxHeight = useLargerValueOfLastTwoValues(appBarHeight);\n const [collapsibleToolbarHeight, onCollapsibleToolbarLayout] = useHeight();\n\n const maxTranslateY = useDerivedValue(() => -collapsibleToolbarHeight, [collapsibleToolbarHeight]);\n\n const translateY = useSharedValue<number>(0);\n const lastTranslateY = useSharedValue<number>(0);\n const lastOffsetY = useSharedValue<number>(0);\n const prevOffsetY = useSharedValue<number>(0);\n const overlapped = useSharedValue<boolean>(false);\n const vectorY = useSharedValue<number>(0);\n\n const elevationStyle = useElevationStyle(4);\n const animatedStyle = useAnimatedStyle(() => {\n const transform = [{ translateY: translateY.value }];\n\n if (Platform.OS === 'web') {\n return {\n transform,\n boxShadow: overlapped.value ? elevationStyle?.boxShadow : 0,\n };\n }\n if (Platform.OS === 'android') {\n return {\n transform,\n elevation: overlapped.value ? elevationStyle?.elevation : 0,\n };\n }\n if (Platform.OS === 'ios') {\n return {\n transform,\n shadowColor: elevationStyle?.shadowColor,\n shadowOffset: elevationStyle?.shadowOffset,\n shadowRadius: elevationStyle?.shadowRadius,\n shadowOpacity: overlapped.value ? elevationStyle?.shadowOpacity : 0,\n };\n }\n return {};\n }, [\n /**\n * FIXME: Consider add `elevationStyle` to dependencies.\n */\n ]);\n\n const indexRef = useRef<number>(0);\n const offsetsRef = useRef<Array<number>>([]);\n\n const onScrollViewChanged = (nextIndex: number) => {\n const prevIndex = indexRef.current;\n if (prevIndex === nextIndex) {\n if (shouldTranslateYReset) {\n translateY.value = withTiming(0, {\n duration: ANIMATION_DURATION_MILLIS,\n });\n\n vectorY.value = 0;\n offsetsRef.current = [];\n overlapped.value = false;\n }\n\n return;\n }\n\n offsetsRef.current[prevIndex] = lastOffsetY.value;\n\n const savedOffsetY = offsetsRef.current[nextIndex] ?? 0;\n lastOffsetY.value = savedOffsetY;\n\n indexRef.current = nextIndex;\n\n // Determine whether to overlap every time index is changed.\n overlapped.value = savedOffsetY > 0;\n\n // If next ScrollView's offset is too short, expand app bar.\n if (translateY.value < 0 && savedOffsetY < appBarHeight) {\n translateY.value = withTiming(0, {\n duration: ANIMATION_DURATION_MILLIS,\n });\n\n vectorY.value = 0;\n }\n };\n\n const scrollHandler = useAnimatedScrollHandler({\n onBeginDrag: () => {\n lastTranslateY.value = translateY.value;\n },\n onMomentumBegin: () => {\n lastTranslateY.value = translateY.value;\n },\n onScroll: (event) => {\n const offsetY = event.contentOffset.y;\n\n const ty = translateY.value;\n const maxTy = maxTranslateY.value;\n\n const deltaY = offsetY - prevOffsetY.value;\n vectorY.value = (vectorY.value * deltaY >= 0 && offsetY > 0) ? vectorY.value + deltaY : deltaY;\n prevOffsetY.value = offsetY;\n\n if (SUPPORTS_DRAG_DETECTION) {\n const dy = offsetY - lastOffsetY.value;\n\n translateY.value = offsetY <= 0 ? 0 : Math.min(Math.max(lastTranslateY.value - dy, maxTy), 0);\n\n overlapped.value = offsetY + translateY.value > 0;\n } else {\n if (offsetY > -maxTy) {\n if (ty === 0) {\n translateY.value = withTiming(Math.min(Math.max(-offsetY, maxTy), 0), {\n duration: ANIMATION_DURATION_MILLIS,\n });\n }\n } else {\n if (ty === maxTy) {\n translateY.value = withTiming(0, {\n duration: ANIMATION_DURATION_MILLIS,\n });\n }\n }\n\n overlapped.value = offsetY > 0;\n\n lastOffsetY.value = offsetY;\n }\n },\n onEndDrag: (event) => {\n lastOffsetY.value = event.contentOffset.y;\n },\n onMomentumEnd: (event) => {\n const offsetY = event.contentOffset.y;\n\n lastOffsetY.value = offsetY;\n\n const ty = translateY.value;\n const maxTy = maxTranslateY.value;\n\n // If toolbar is already positioned on edge, do nothing.\n if (ty <= maxTy || ty >= 0) {\n return;\n }\n\n const threshold = maxTy * 0.5;\n\n const nextTranslateY = (ty > threshold || offsetY < appBarHeight) ? 0 : maxTy;\n\n overlapped.value = offsetY + nextTranslateY > 0;\n\n translateY.value = withTiming(nextTranslateY, {\n duration: ANIMATION_DURATION_MILLIS,\n });\n },\n }, []);\n\n const hasCollapsible = collapsibleToolbarHeight > 0;\n\n const appBarStyle = [\n animatedStyle,\n { paddingTop: safeAreaInsets.top },\n hasCollapsible ? styles.floating : undefined,\n ];\n\n return {\n appBarStyle,\n vectorY,\n onAppBarLayout,\n onCollapsibleToolbarLayout,\n onScroll: scrollHandler,\n onScrollViewChanged,\n scrollContentIns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AACrB,KAAX,GAAmB4C,OAAO,GAAGW,cAAV,GAA2B,CAA9C;MAEAtC,UAAU,CAACjB,KAAX,GAAmBX,UAAU,CAACkE,cAAD,EAAiB;QAC1ClB,QAAQ,EAAEzC;MADgC,CAAjB,CAA7B;IAGH;EApE0C,CAAD,EAqE3C,EArE2C,CAA9C;EAuEA,MAAM4D,cAAc,GAAG1C,wBAAwB,GAAG,CAAlD;EAEA,MAAM2C,WAAW,GAAG,CAChBjC,aADgB,EAEhB;IAAEkC,UAAU,EAAEhD,cAAc,CAACiD;EAA7B,CAFgB,EAGhBH,cAAc,GAAG/C,MAAM,CAACmD,QAAV,GAAqBC,SAHnB,CAApB;EAMA,OAAO;IACHJ,WADG;IAEHnC,OAFG;IAGHV,cAHG;IAIHG,0BAJG;IAKH2B,QAAQ,EAAEH,aALP;IAMHL,mBANG;IAOH4B,mBAAmB,EAAE;MAAEH,GAAG,EAAEH,cAAc,GAAG3C,eAAH,GAAqB;IAA1C;EAPlB,CAAP;AASH;AAAA"}
@@ -9,10 +9,10 @@ export default function useAnimatedDisplayStyle(vectorY) {
9
9
  } else if (vy < threshold) {
10
10
  display.value = 'flex';
11
11
  }
12
- });
12
+ }, [threshold]);
13
13
  return useAnimatedStyle(() => ({
14
14
  display: display.value
15
- }));
15
+ }), []);
16
16
  }
17
17
  ;
18
18
  //# sourceMappingURL=useUnstableToggleDisplayStyle.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["useAnimatedReaction","useAnimatedStyle","useSharedValue","useAnimatedDisplayStyle","vectorY","threshold","defaultDisplay","display","value","vy"],"sources":["useUnstableToggleDisplayStyle.ts"],"sourcesContent":["import type { SharedValue } from 'react-native-reanimated';\nimport { useAnimatedReaction, useAnimatedStyle, useSharedValue } from 'react-native-reanimated';\n\nexport default function useAnimatedDisplayStyle(\n vectorY: SharedValue<number>,\n threshold: number = 200,\n defaultDisplay: 'flex' | 'none' = 'flex',\n) {\n const display = useSharedValue(defaultDisplay);\n\n useAnimatedReaction(\n () => vectorY.value,\n (vy) => {\n if (vy >= threshold) {\n display.value = 'none';\n } else if (vy < threshold) {\n display.value = 'flex';\n }\n },\n );\n\n return useAnimatedStyle(() => ({\n display: display.value,\n }));\n};\n"],"mappings":"AACA,SAASA,mBAAT,EAA8BC,gBAA9B,EAAgDC,cAAhD,QAAsE,yBAAtE;AAEA,eAAe,SAASC,uBAAT,CACXC,OADW,EAIb;EAAA,IAFEC,SAEF,uEAFsB,GAEtB;EAAA,IADEC,cACF,uEADoC,MACpC;EACE,MAAMC,OAAO,GAAGL,cAAc,CAACI,cAAD,CAA9B;EAEAN,mBAAmB,CACf,MAAMI,OAAO,CAACI,KADC,EAEdC,EAAD,IAAQ;IACJ,IAAIA,EAAE,IAAIJ,SAAV,EAAqB;MACjBE,OAAO,CAACC,KAAR,GAAgB,MAAhB;IACH,CAFD,MAEO,IAAIC,EAAE,GAAGJ,SAAT,EAAoB;MACvBE,OAAO,CAACC,KAAR,GAAgB,MAAhB;IACH;EACJ,CARc,CAAnB;EAWA,OAAOP,gBAAgB,CAAC,OAAO;IAC3BM,OAAO,EAAEA,OAAO,CAACC;EADU,CAAP,CAAD,CAAvB;AAGH;AAAA"}
1
+ {"version":3,"names":["useAnimatedReaction","useAnimatedStyle","useSharedValue","useAnimatedDisplayStyle","vectorY","threshold","defaultDisplay","display","value","vy"],"sources":["useUnstableToggleDisplayStyle.ts"],"sourcesContent":["import type { SharedValue } from 'react-native-reanimated';\nimport { useAnimatedReaction, useAnimatedStyle, useSharedValue } from 'react-native-reanimated';\n\nexport default function useAnimatedDisplayStyle(\n vectorY: SharedValue<number>,\n threshold: number = 200,\n defaultDisplay: 'flex' | 'none' = 'flex',\n) {\n const display = useSharedValue(defaultDisplay);\n\n useAnimatedReaction(\n () => vectorY.value,\n (vy) => {\n if (vy >= threshold) {\n display.value = 'none';\n } else if (vy < threshold) {\n display.value = 'flex';\n }\n },\n [threshold],\n );\n\n return useAnimatedStyle(() => ({\n display: display.value,\n }), []);\n};\n"],"mappings":"AACA,SAASA,mBAAT,EAA8BC,gBAA9B,EAAgDC,cAAhD,QAAsE,yBAAtE;AAEA,eAAe,SAASC,uBAAT,CACXC,OADW,EAIb;EAAA,IAFEC,SAEF,uEAFsB,GAEtB;EAAA,IADEC,cACF,uEADoC,MACpC;EACE,MAAMC,OAAO,GAAGL,cAAc,CAACI,cAAD,CAA9B;EAEAN,mBAAmB,CACf,MAAMI,OAAO,CAACI,KADC,EAEdC,EAAD,IAAQ;IACJ,IAAIA,EAAE,IAAIJ,SAAV,EAAqB;MACjBE,OAAO,CAACC,KAAR,GAAgB,MAAhB;IACH,CAFD,MAEO,IAAIC,EAAE,GAAGJ,SAAT,EAAoB;MACvBE,OAAO,CAACC,KAAR,GAAgB,MAAhB;IACH;EACJ,CARc,EASf,CAACH,SAAD,CATe,CAAnB;EAYA,OAAOJ,gBAAgB,CAAC,OAAO;IAC3BM,OAAO,EAAEA,OAAO,CAACC;EADU,CAAP,CAAD,EAEnB,EAFmB,CAAvB;AAGH;AAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fountain-ui/lab",
3
- "version": "2.0.0-beta.8",
3
+ "version": "2.0.0-beta.9",
4
4
  "private": false,
5
5
  "author": "Fountain-UI Team",
6
6
  "description": "Incubator for Fountain-UI React components.",
@@ -85,5 +85,5 @@
85
85
  "publishConfig": {
86
86
  "access": "public"
87
87
  },
88
- "gitHead": "3de48896d62f1ba687558ea11b5f527cb91b5da6"
88
+ "gitHead": "319e9f913cea57c5570e8b09a9ce410b3914d4f7"
89
89
  }
@@ -1,7 +1,13 @@
1
- import React from 'react';
1
+ import React, { useEffect } from 'react';
2
+ import type { WithTimingConfig } from 'react-native-reanimated';
2
3
  import Animated, { Easing, useAnimatedStyle, useSharedValue, withTiming } from 'react-native-reanimated';
3
4
  import type AnimatedYProps from './AnimatedYProps';
4
5
 
6
+ const ANIMATION_CONFIG: Readonly<WithTimingConfig> = {
7
+ duration: 150,
8
+ easing: Easing.out(Easing.exp),
9
+ };
10
+
5
11
  export default function AnimatedY(props: AnimatedYProps) {
6
12
  const {
7
13
  children,
@@ -12,14 +18,11 @@ export default function AnimatedY(props: AnimatedYProps) {
12
18
  const animatedY = useSharedValue(translateY);
13
19
  const animatedStyle = useAnimatedStyle(() => ({
14
20
  transform: [{ translateY: animatedY.value }],
15
- }));
21
+ }), []);
16
22
 
17
- React.useEffect(() => {
23
+ useEffect(() => {
18
24
  if (translateY >= 0) {
19
- animatedY.value = withTiming(translateY, {
20
- duration: 150,
21
- easing: Easing.out(Easing.exp),
22
- });
25
+ animatedY.value = withTiming(translateY, ANIMATION_CONFIG);
23
26
  }
24
27
  }, [translateY]);
25
28
 
@@ -37,7 +37,7 @@ export default function FlipCard(props: FlipCardProps) {
37
37
  { rotateX: `${sharedAngle.value}deg` },
38
38
  ],
39
39
  };
40
- });
40
+ }, []);
41
41
 
42
42
  const animatedBackCardStyle = useAnimatedStyle(() => {
43
43
  return {
@@ -47,7 +47,7 @@ export default function FlipCard(props: FlipCardProps) {
47
47
  { rotateX: `${(sharedAngle.value + 180)}deg` },
48
48
  ],
49
49
  };
50
- });
50
+ }, []);
51
51
 
52
52
  useEffect(() => {
53
53
  sharedAngle.value = 0;
@@ -1,4 +1,4 @@
1
- import React, { useRef } from 'react';
1
+ import { useRef } from 'react';
2
2
  import { Falsy, Platform, RegisteredStyle, ScrollViewProps, ViewProps, ViewStyle } from 'react-native';
3
3
  import type { SharedValue } from 'react-native-reanimated';
4
4
  import {
@@ -50,7 +50,6 @@ const ANIMATION_DURATION_MILLIS = 100;
50
50
 
51
51
  const SUPPORTS_DRAG_DETECTION = Platform.OS !== 'web';
52
52
 
53
-
54
53
  function useLargerValueOfLastTwoValues(value: number) {
55
54
  const refLatestTwoValues = useRef([0, 0]);
56
55
 
@@ -60,7 +59,6 @@ function useLargerValueOfLastTwoValues(value: number) {
60
59
  return Math.max(...refLatestTwoValues.current);
61
60
  }
62
61
 
63
-
64
62
  export default function useUnstableCollapsibleAppBar(userOptions: Options = defaultOptions): CollapsibleAppBar {
65
63
  const { shouldTranslateYReset }: Required<Options> = {
66
64
  ...defaultOptions,
@@ -75,7 +73,7 @@ export default function useUnstableCollapsibleAppBar(userOptions: Options = defa
75
73
  const appBarMaxHeight = useLargerValueOfLastTwoValues(appBarHeight);
76
74
  const [collapsibleToolbarHeight, onCollapsibleToolbarLayout] = useHeight();
77
75
 
78
- const maxTranslateY = useDerivedValue(() => -collapsibleToolbarHeight);
76
+ const maxTranslateY = useDerivedValue(() => -collapsibleToolbarHeight, [collapsibleToolbarHeight]);
79
77
 
80
78
  const translateY = useSharedValue<number>(0);
81
79
  const lastTranslateY = useSharedValue<number>(0);
@@ -86,21 +84,23 @@ export default function useUnstableCollapsibleAppBar(userOptions: Options = defa
86
84
 
87
85
  const elevationStyle = useElevationStyle(4);
88
86
  const animatedStyle = useAnimatedStyle(() => {
87
+ const transform = [{ translateY: translateY.value }];
88
+
89
89
  if (Platform.OS === 'web') {
90
90
  return {
91
- transform: [{ translateY: translateY.value }],
91
+ transform,
92
92
  boxShadow: overlapped.value ? elevationStyle?.boxShadow : 0,
93
93
  };
94
94
  }
95
95
  if (Platform.OS === 'android') {
96
96
  return {
97
- transform: [{ translateY: translateY.value }],
97
+ transform,
98
98
  elevation: overlapped.value ? elevationStyle?.elevation : 0,
99
99
  };
100
100
  }
101
101
  if (Platform.OS === 'ios') {
102
102
  return {
103
- transform: [{ translateY: translateY.value }],
103
+ transform,
104
104
  shadowColor: elevationStyle?.shadowColor,
105
105
  shadowOffset: elevationStyle?.shadowOffset,
106
106
  shadowRadius: elevationStyle?.shadowRadius,
@@ -108,10 +108,14 @@ export default function useUnstableCollapsibleAppBar(userOptions: Options = defa
108
108
  };
109
109
  }
110
110
  return {};
111
- });
111
+ }, [
112
+ /**
113
+ * FIXME: Consider add `elevationStyle` to dependencies.
114
+ */
115
+ ]);
112
116
 
113
- const indexRef = React.useRef<number>(0);
114
- const offsetsRef = React.useRef<Array<number>>([]);
117
+ const indexRef = useRef<number>(0);
118
+ const offsetsRef = useRef<Array<number>>([]);
115
119
 
116
120
  const onScrollViewChanged = (nextIndex: number) => {
117
121
  const prevIndex = indexRef.current;
@@ -218,7 +222,7 @@ export default function useUnstableCollapsibleAppBar(userOptions: Options = defa
218
222
  duration: ANIMATION_DURATION_MILLIS,
219
223
  });
220
224
  },
221
- });
225
+ }, []);
222
226
 
223
227
  const hasCollapsible = collapsibleToolbarHeight > 0;
224
228
 
@@ -17,9 +17,10 @@ export default function useAnimatedDisplayStyle(
17
17
  display.value = 'flex';
18
18
  }
19
19
  },
20
+ [threshold],
20
21
  );
21
22
 
22
23
  return useAnimatedStyle(() => ({
23
24
  display: display.value,
24
- }));
25
+ }), []);
25
26
  };