@hero-design/rn 8.118.0 → 8.118.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @hero-design/rn
2
2
 
3
+ ## 8.118.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#4719](https://github.com/Thinkei/hero-design/pull/4719) [`2d4e3f901018d95280909eac099ad387982ff1b7`](https://github.com/Thinkei/hero-design/commit/2d4e3f901018d95280909eac099ad387982ff1b7) Thanks [@ttkien](https://github.com/ttkien)! - [FAB] Fix redundant FAB button with bottom navigation
8
+
3
9
  ## 8.118.0
4
10
 
5
11
  ### Minor Changes
package/es/index.js CHANGED
@@ -23774,7 +23774,7 @@ var FAB$1 = /*#__PURE__*/forwardRef(function (_ref3, ref) {
23774
23774
  var onPress = _ref3.onPress,
23775
23775
  title = _ref3.title,
23776
23776
  icon = _ref3.icon,
23777
- animated = _ref3.animated,
23777
+ iconAnimated = _ref3.animated,
23778
23778
  testID = _ref3.testID,
23779
23779
  active = _ref3.active,
23780
23780
  style = _ref3.style;
@@ -23801,49 +23801,78 @@ var FAB$1 = /*#__PURE__*/forwardRef(function (_ref3, ref) {
23801
23801
  React__default.useImperativeHandle(ref, function () {
23802
23802
  return {
23803
23803
  show: function show() {
23804
- Animated.spring(animatedValues.translateY, {
23805
- toValue: 0,
23806
- useNativeDriver: true
23807
- }).start();
23804
+ var animated = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
23805
+ var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop$2;
23808
23806
  setDisplayState({
23809
23807
  hideButton: false,
23810
23808
  hideTitle: false
23811
23809
  });
23812
23810
  animateWidth();
23813
- Animated.spring(animatedValues.opacity, {
23814
- toValue: 1,
23815
- useNativeDriver: true
23816
- }).start();
23811
+ if (animated) {
23812
+ Animated.parallel([Animated.spring(animatedValues.opacity, {
23813
+ toValue: 1,
23814
+ useNativeDriver: true
23815
+ }), Animated.spring(animatedValues.translateY, {
23816
+ toValue: 0,
23817
+ useNativeDriver: true
23818
+ })]).start(callback);
23819
+ } else {
23820
+ animatedValues.opacity.setValue(1);
23821
+ animatedValues.translateY.setValue(0);
23822
+ }
23817
23823
  },
23818
23824
  collapse: function collapse() {
23819
- Animated.parallel([Animated.spring(animatedValues.opacity, {
23820
- toValue: 1,
23821
- useNativeDriver: true
23822
- }), Animated.spring(animatedValues.translateY, {
23823
- toValue: 0,
23824
- useNativeDriver: true
23825
- })]).start();
23826
- animateWidth();
23825
+ var animated = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
23826
+ var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop$2;
23827
23827
  setDisplayState({
23828
23828
  hideButton: false,
23829
23829
  hideTitle: true
23830
23830
  });
23831
+ animateWidth();
23832
+ if (animated) {
23833
+ Animated.parallel([Animated.spring(animatedValues.opacity, {
23834
+ toValue: 1,
23835
+ useNativeDriver: true
23836
+ }), Animated.spring(animatedValues.translateY, {
23837
+ toValue: 0,
23838
+ useNativeDriver: true
23839
+ })]).start(callback);
23840
+ } else {
23841
+ animatedValues.opacity.setValue(1);
23842
+ animatedValues.translateY.setValue(0);
23843
+ }
23831
23844
  },
23832
23845
  hide: function hide() {
23833
- Animated.stagger(20, [Animated.spring(animatedValues.opacity, {
23834
- toValue: 0,
23835
- useNativeDriver: true
23836
- }), Animated.spring(animatedValues.translateY, {
23837
- toValue: 1,
23838
- useNativeDriver: true
23839
- })]).start(function () {
23846
+ var animated = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
23847
+ var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop$2;
23848
+ if (animated) {
23849
+ Animated.stagger(20, [Animated.spring(animatedValues.opacity, {
23850
+ toValue: 0,
23851
+ useNativeDriver: true
23852
+ }), Animated.spring(animatedValues.translateY, {
23853
+ toValue: 1,
23854
+ useNativeDriver: true
23855
+ })]).start(function (arg) {
23856
+ animateWidth();
23857
+ setDisplayState(function (previousState) {
23858
+ return _objectSpread2(_objectSpread2({}, previousState), {}, {
23859
+ hideButton: true
23860
+ });
23861
+ });
23862
+ if (callback) {
23863
+ callback(arg);
23864
+ }
23865
+ });
23866
+ } else {
23867
+ animatedValues.opacity.setValue(0);
23868
+ animatedValues.translateY.setValue(1);
23840
23869
  animateWidth();
23841
23870
  setDisplayState(function (previousState) {
23842
23871
  return _objectSpread2(_objectSpread2({}, previousState), {}, {
23843
23872
  hideButton: true
23844
23873
  });
23845
23874
  });
23846
- });
23875
+ }
23847
23876
  }
23848
23877
  };
23849
23878
  }, []);
@@ -23873,7 +23902,7 @@ var FAB$1 = /*#__PURE__*/forwardRef(function (_ref3, ref) {
23873
23902
  })
23874
23903
  }
23875
23904
  }, isIconOnly ? /*#__PURE__*/React__default.createElement(IconOnlyContent, {
23876
- animated: animated,
23905
+ animated: iconAnimated,
23877
23906
  active: active,
23878
23907
  icon: active ? 'add' : icon
23879
23908
  }) : /*#__PURE__*/React__default.createElement(IconWithTextContent, {
@@ -23972,15 +24001,18 @@ var ActionGroup = /*#__PURE__*/forwardRef(function (_ref, ref) {
23972
24001
  React__default.useEffect(function () {
23973
24002
  Animated.spring(animatedValue.current, {
23974
24003
  toValue: active ? 1 : 0,
23975
- delay: 100,
23976
24004
  useNativeDriver: Platform.OS !== 'web'
23977
24005
  }).start();
23978
24006
  if (active) {
23979
24007
  var _fabRef$current4;
23980
- (_fabRef$current4 = fabRef.current) === null || _fabRef$current4 === void 0 || _fabRef$current4.collapse();
24008
+ (_fabRef$current4 = fabRef.current) === null || _fabRef$current4 === void 0 || _fabRef$current4.collapse(true, function () {
24009
+ var _fabRef$current5;
24010
+ (_fabRef$current5 = fabRef.current) === null || _fabRef$current5 === void 0 || _fabRef$current5.hide(false);
24011
+ });
23981
24012
  } else {
23982
- var _fabRef$current5;
23983
- (_fabRef$current5 = fabRef.current) === null || _fabRef$current5 === void 0 || _fabRef$current5.show();
24013
+ var _fabRef$current6, _fabRef$current7;
24014
+ (_fabRef$current6 = fabRef.current) === null || _fabRef$current6 === void 0 || _fabRef$current6.collapse(false);
24015
+ (_fabRef$current7 = fabRef.current) === null || _fabRef$current7 === void 0 || _fabRef$current7.show();
23984
24016
  }
23985
24017
  }, [active]);
23986
24018
  var actionGroupOpacity = animatedValue.current.interpolate({
package/lib/index.js CHANGED
@@ -23803,7 +23803,7 @@ var FAB$1 = /*#__PURE__*/React.forwardRef(function (_ref3, ref) {
23803
23803
  var onPress = _ref3.onPress,
23804
23804
  title = _ref3.title,
23805
23805
  icon = _ref3.icon,
23806
- animated = _ref3.animated,
23806
+ iconAnimated = _ref3.animated,
23807
23807
  testID = _ref3.testID,
23808
23808
  active = _ref3.active,
23809
23809
  style = _ref3.style;
@@ -23830,49 +23830,78 @@ var FAB$1 = /*#__PURE__*/React.forwardRef(function (_ref3, ref) {
23830
23830
  React__namespace.default.useImperativeHandle(ref, function () {
23831
23831
  return {
23832
23832
  show: function show() {
23833
- reactNative.Animated.spring(animatedValues.translateY, {
23834
- toValue: 0,
23835
- useNativeDriver: true
23836
- }).start();
23833
+ var animated = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
23834
+ var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop$2;
23837
23835
  setDisplayState({
23838
23836
  hideButton: false,
23839
23837
  hideTitle: false
23840
23838
  });
23841
23839
  animateWidth();
23842
- reactNative.Animated.spring(animatedValues.opacity, {
23843
- toValue: 1,
23844
- useNativeDriver: true
23845
- }).start();
23840
+ if (animated) {
23841
+ reactNative.Animated.parallel([reactNative.Animated.spring(animatedValues.opacity, {
23842
+ toValue: 1,
23843
+ useNativeDriver: true
23844
+ }), reactNative.Animated.spring(animatedValues.translateY, {
23845
+ toValue: 0,
23846
+ useNativeDriver: true
23847
+ })]).start(callback);
23848
+ } else {
23849
+ animatedValues.opacity.setValue(1);
23850
+ animatedValues.translateY.setValue(0);
23851
+ }
23846
23852
  },
23847
23853
  collapse: function collapse() {
23848
- reactNative.Animated.parallel([reactNative.Animated.spring(animatedValues.opacity, {
23849
- toValue: 1,
23850
- useNativeDriver: true
23851
- }), reactNative.Animated.spring(animatedValues.translateY, {
23852
- toValue: 0,
23853
- useNativeDriver: true
23854
- })]).start();
23855
- animateWidth();
23854
+ var animated = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
23855
+ var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop$2;
23856
23856
  setDisplayState({
23857
23857
  hideButton: false,
23858
23858
  hideTitle: true
23859
23859
  });
23860
+ animateWidth();
23861
+ if (animated) {
23862
+ reactNative.Animated.parallel([reactNative.Animated.spring(animatedValues.opacity, {
23863
+ toValue: 1,
23864
+ useNativeDriver: true
23865
+ }), reactNative.Animated.spring(animatedValues.translateY, {
23866
+ toValue: 0,
23867
+ useNativeDriver: true
23868
+ })]).start(callback);
23869
+ } else {
23870
+ animatedValues.opacity.setValue(1);
23871
+ animatedValues.translateY.setValue(0);
23872
+ }
23860
23873
  },
23861
23874
  hide: function hide() {
23862
- reactNative.Animated.stagger(20, [reactNative.Animated.spring(animatedValues.opacity, {
23863
- toValue: 0,
23864
- useNativeDriver: true
23865
- }), reactNative.Animated.spring(animatedValues.translateY, {
23866
- toValue: 1,
23867
- useNativeDriver: true
23868
- })]).start(function () {
23875
+ var animated = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
23876
+ var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop$2;
23877
+ if (animated) {
23878
+ reactNative.Animated.stagger(20, [reactNative.Animated.spring(animatedValues.opacity, {
23879
+ toValue: 0,
23880
+ useNativeDriver: true
23881
+ }), reactNative.Animated.spring(animatedValues.translateY, {
23882
+ toValue: 1,
23883
+ useNativeDriver: true
23884
+ })]).start(function (arg) {
23885
+ animateWidth();
23886
+ setDisplayState(function (previousState) {
23887
+ return _objectSpread2(_objectSpread2({}, previousState), {}, {
23888
+ hideButton: true
23889
+ });
23890
+ });
23891
+ if (callback) {
23892
+ callback(arg);
23893
+ }
23894
+ });
23895
+ } else {
23896
+ animatedValues.opacity.setValue(0);
23897
+ animatedValues.translateY.setValue(1);
23869
23898
  animateWidth();
23870
23899
  setDisplayState(function (previousState) {
23871
23900
  return _objectSpread2(_objectSpread2({}, previousState), {}, {
23872
23901
  hideButton: true
23873
23902
  });
23874
23903
  });
23875
- });
23904
+ }
23876
23905
  }
23877
23906
  };
23878
23907
  }, []);
@@ -23902,7 +23931,7 @@ var FAB$1 = /*#__PURE__*/React.forwardRef(function (_ref3, ref) {
23902
23931
  })
23903
23932
  }
23904
23933
  }, isIconOnly ? /*#__PURE__*/React__namespace.default.createElement(IconOnlyContent, {
23905
- animated: animated,
23934
+ animated: iconAnimated,
23906
23935
  active: active,
23907
23936
  icon: active ? 'add' : icon
23908
23937
  }) : /*#__PURE__*/React__namespace.default.createElement(IconWithTextContent, {
@@ -24001,15 +24030,18 @@ var ActionGroup = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
24001
24030
  React__namespace.default.useEffect(function () {
24002
24031
  reactNative.Animated.spring(animatedValue.current, {
24003
24032
  toValue: active ? 1 : 0,
24004
- delay: 100,
24005
24033
  useNativeDriver: reactNative.Platform.OS !== 'web'
24006
24034
  }).start();
24007
24035
  if (active) {
24008
24036
  var _fabRef$current4;
24009
- (_fabRef$current4 = fabRef.current) === null || _fabRef$current4 === void 0 || _fabRef$current4.collapse();
24037
+ (_fabRef$current4 = fabRef.current) === null || _fabRef$current4 === void 0 || _fabRef$current4.collapse(true, function () {
24038
+ var _fabRef$current5;
24039
+ (_fabRef$current5 = fabRef.current) === null || _fabRef$current5 === void 0 || _fabRef$current5.hide(false);
24040
+ });
24010
24041
  } else {
24011
- var _fabRef$current5;
24012
- (_fabRef$current5 = fabRef.current) === null || _fabRef$current5 === void 0 || _fabRef$current5.show();
24042
+ var _fabRef$current6, _fabRef$current7;
24043
+ (_fabRef$current6 = fabRef.current) === null || _fabRef$current6 === void 0 || _fabRef$current6.collapse(false);
24044
+ (_fabRef$current7 = fabRef.current) === null || _fabRef$current7 === void 0 || _fabRef$current7.show();
24013
24045
  }
24014
24046
  }, [active]);
24015
24047
  var actionGroupOpacity = animatedValue.current.interpolate({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hero-design/rn",
3
- "version": "8.118.0",
3
+ "version": "8.118.1",
4
4
  "license": "MIT",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -113,13 +113,15 @@ const ActionGroup = forwardRef<ActionGroupHandles, ActionGroupProps>(
113
113
  React.useEffect(() => {
114
114
  Animated.spring(animatedValue.current, {
115
115
  toValue: active ? 1 : 0,
116
- delay: 100,
117
116
  useNativeDriver: Platform.OS !== 'web',
118
117
  }).start();
119
118
 
120
119
  if (active) {
121
- fabRef.current?.collapse();
120
+ fabRef.current?.collapse(true, () => {
121
+ fabRef.current?.hide(false);
122
+ });
122
123
  } else {
124
+ fabRef.current?.collapse(false);
123
125
  fabRef.current?.show();
124
126
  }
125
127
  }, [active]);
@@ -16,11 +16,12 @@ import {
16
16
  StyledFABText,
17
17
  StyledIconContainer,
18
18
  } from './StyledFAB';
19
+ import { noop } from '../../utils/functions';
19
20
 
20
21
  export type FABHandles = {
21
- show: () => void;
22
- collapse: () => void;
23
- hide: () => void;
22
+ show: (animated?: boolean, callback?: Animated.EndCallback) => void;
23
+ collapse: (animated?: boolean, callback?: Animated.EndCallback) => void;
24
+ hide: (animated?: boolean, callback?: Animated.EndCallback) => void;
24
25
  };
25
26
 
26
27
  if (Platform.OS === 'android') {
@@ -120,7 +121,10 @@ const animateWidth = () => {
120
121
  };
121
122
 
122
123
  const FAB = forwardRef<FABHandles, FABProps>(
123
- ({ onPress, title, icon, animated, testID, active, style }, ref) => {
124
+ (
125
+ { onPress, title, icon, animated: iconAnimated, testID, active, style },
126
+ ref
127
+ ) => {
124
128
  const theme = useTheme();
125
129
  const [displayState, setDisplayState] = React.useState({
126
130
  hideTitle: false,
@@ -141,12 +145,7 @@ const FAB = forwardRef<FABHandles, FABProps>(
141
145
  React.useImperativeHandle(
142
146
  ref,
143
147
  () => ({
144
- show: () => {
145
- Animated.spring(animatedValues.translateY, {
146
- toValue: 0,
147
- useNativeDriver: true,
148
- }).start();
149
-
148
+ show: (animated = true, callback: Animated.EndCallback = noop) => {
150
149
  setDisplayState({
151
150
  hideButton: false,
152
151
  hideTitle: false,
@@ -154,47 +153,76 @@ const FAB = forwardRef<FABHandles, FABProps>(
154
153
 
155
154
  animateWidth();
156
155
 
157
- Animated.spring(animatedValues.opacity, {
158
- toValue: 1,
159
- useNativeDriver: true,
160
- }).start();
156
+ if (animated) {
157
+ Animated.parallel([
158
+ Animated.spring(animatedValues.opacity, {
159
+ toValue: 1,
160
+ useNativeDriver: true,
161
+ }),
162
+ Animated.spring(animatedValues.translateY, {
163
+ toValue: 0,
164
+ useNativeDriver: true,
165
+ }),
166
+ ]).start(callback);
167
+ } else {
168
+ animatedValues.opacity.setValue(1);
169
+ animatedValues.translateY.setValue(0);
170
+ }
161
171
  },
162
- collapse: () => {
163
- Animated.parallel([
164
- Animated.spring(animatedValues.opacity, {
165
- toValue: 1,
166
- useNativeDriver: true,
167
- }),
168
- Animated.spring(animatedValues.translateY, {
169
- toValue: 0,
170
- useNativeDriver: true,
171
- }),
172
- ]).start();
173
-
174
- animateWidth();
175
-
172
+ collapse: (animated = true, callback: Animated.EndCallback = noop) => {
176
173
  setDisplayState({
177
174
  hideButton: false,
178
175
  hideTitle: true,
179
176
  });
177
+
178
+ animateWidth();
179
+
180
+ if (animated) {
181
+ Animated.parallel([
182
+ Animated.spring(animatedValues.opacity, {
183
+ toValue: 1,
184
+ useNativeDriver: true,
185
+ }),
186
+ Animated.spring(animatedValues.translateY, {
187
+ toValue: 0,
188
+ useNativeDriver: true,
189
+ }),
190
+ ]).start(callback);
191
+ } else {
192
+ animatedValues.opacity.setValue(1);
193
+ animatedValues.translateY.setValue(0);
194
+ }
180
195
  },
181
- hide: () => {
182
- Animated.stagger(20, [
183
- Animated.spring(animatedValues.opacity, {
184
- toValue: 0,
185
- useNativeDriver: true,
186
- }),
187
- Animated.spring(animatedValues.translateY, {
188
- toValue: 1,
189
- useNativeDriver: true,
190
- }),
191
- ]).start(() => {
196
+ hide: (animated = true, callback: Animated.EndCallback = noop) => {
197
+ if (animated) {
198
+ Animated.stagger(20, [
199
+ Animated.spring(animatedValues.opacity, {
200
+ toValue: 0,
201
+ useNativeDriver: true,
202
+ }),
203
+ Animated.spring(animatedValues.translateY, {
204
+ toValue: 1,
205
+ useNativeDriver: true,
206
+ }),
207
+ ]).start((arg) => {
208
+ animateWidth();
209
+ setDisplayState((previousState) => ({
210
+ ...previousState,
211
+ hideButton: true,
212
+ }));
213
+ if (callback) {
214
+ callback(arg);
215
+ }
216
+ });
217
+ } else {
218
+ animatedValues.opacity.setValue(0);
219
+ animatedValues.translateY.setValue(1);
192
220
  animateWidth();
193
221
  setDisplayState((previousState) => ({
194
222
  ...previousState,
195
223
  hideButton: true,
196
224
  }));
197
- });
225
+ }
198
226
  },
199
227
  }),
200
228
  []
@@ -243,7 +271,7 @@ const FAB = forwardRef<FABHandles, FABProps>(
243
271
  >
244
272
  {isIconOnly ? (
245
273
  <IconOnlyContent
246
- animated={animated}
274
+ animated={iconAnimated}
247
275
  active={active}
248
276
  icon={active ? 'add' : icon}
249
277
  />
@@ -9,10 +9,11 @@ jest.mock('react-native-vector-icons', () => ({
9
9
 
10
10
  jest.mock('react-native', () => {
11
11
  const RN = jest.requireActual('react-native');
12
-
13
12
  const mockedAnimatedFunctions = {
14
13
  setImmediate: () => jest.fn(),
15
- start: () => jest.fn(),
14
+ start: jest.fn((callback?: (result: { finished: boolean }) => void) => {
15
+ callback?.({ finished: true });
16
+ }),
16
17
  stop: () => jest.fn(),
17
18
  _isUsingNativeDriver: () => jest.fn(),
18
19
  _startNativeLoop: () => jest.fn(),
@@ -1,10 +1,11 @@
1
1
  import React from 'react';
2
2
  import type { StyleProp, ViewStyle } from 'react-native';
3
+ import { Animated } from 'react-native';
3
4
  import type { IconName } from '../Icon';
4
5
  export type FABHandles = {
5
- show: () => void;
6
- collapse: () => void;
7
- hide: () => void;
6
+ show: (animated?: boolean, callback?: Animated.EndCallback) => void;
7
+ collapse: (animated?: boolean, callback?: Animated.EndCallback) => void;
8
+ hide: (animated?: boolean, callback?: Animated.EndCallback) => void;
8
9
  };
9
10
  export interface FABProps {
10
11
  /**