sapo-components-ui-rn 1.1.87 → 1.1.88

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/README.md CHANGED
@@ -19,22 +19,21 @@ Thư viện này yêu cầu các peer dependencies sau:
19
19
  "react": ">=18.0.0",
20
20
  "react-native": ">=0.70.0",
21
21
  "@react-native-community/masked-view": "*",
22
+ "react-native-gesture-handler": "*",
23
+ "react-native-reanimated": "*",
22
24
  "react-native-safe-area-context": "*",
23
- "react-native-screens": "*",
24
- "react-native-svg": "*"
25
+ "react-native-screens": "*"
25
26
  }
26
27
  ```
27
28
 
28
29
  ## Sử dụng
29
30
 
30
31
  ```tsx
31
- import { Button, ToastProvider } from 'sapo-components-ui-rn';
32
+ import { Button } from '@sapo/components-ui-rn';
32
33
 
33
- function App() {
34
+ function MyComponent() {
34
35
  return (
35
- <ToastProvider>
36
- <Button title="My Button" onPress={() => {}} />
37
- </ToastProvider>
36
+ <Button disabled textStyle={{...}} title="My Button" onPress={()=> {}}/>
38
37
  );
39
38
  }
40
39
  ```
@@ -1 +1 @@
1
- export declare const IMAGE_DEFAULT: any;
1
+ export declare const getImageDefault: () => number;
@@ -1 +1,9 @@
1
- export const IMAGE_DEFAULT = require('./image_default.png');
1
+ /* eslint-disable @typescript-eslint/no-var-requires */
2
+ let imageDefault: number | undefined;
3
+
4
+ export const getImageDefault = (): number => {
5
+ if (imageDefault === undefined) {
6
+ imageDefault = require("./image_default.png");
7
+ }
8
+ return imageDefault;
9
+ };
@@ -14,7 +14,7 @@ interface ToastProviderProps {
14
14
  children: React.ReactNode;
15
15
  /**
16
16
  * Nếu ứng dụng đã có SafeAreaProvider, set wrapSafeArea = false
17
- * @default false
17
+ * @default true
18
18
  */
19
19
  wrapSafeArea?: boolean;
20
20
  }
@@ -7,7 +7,7 @@ export declare const ThemeProvider: ({ children }: {
7
7
  children: React.ReactNode;
8
8
  }) => React.JSX.Element;
9
9
  export declare function useTheme<T = AppTheme>(overrides?: $DeepPartial<T>): T;
10
- export declare const useInternalTheme: () => InternalTheme;
10
+ export declare const useInternalTheme: () => AppTheme;
11
11
  export declare const withInternalTheme: <Props extends {
12
12
  theme: InternalTheme;
13
13
  }, C>(WrappedComponent: ComponentType<Props & {
package/dist/index.esm.js CHANGED
@@ -1,7 +1,8 @@
1
- import { Platform, StyleSheet, Dimensions, TouchableOpacity, View as View$1, Animated, Text as Text$2, Pressable, I18nManager, useWindowDimensions, TextInput as TextInput$1, Modal, Keyboard, ActivityIndicator, ImageBackground, Image as Image$2 } from 'react-native';
1
+ import { Dimensions, Platform, StyleSheet, useColorScheme, TouchableOpacity, View as View$1, Text as Text$2, Animated as Animated$1, Pressable, I18nManager, useWindowDimensions, TextInput as TextInput$1, Modal, Keyboard, ActivityIndicator, ImageBackground, Image as Image$2 } from 'react-native';
2
2
  import * as React$3 from 'react';
3
- import React__default, { forwardRef as forwardRef$1, memo, useRef, useEffect, useCallback, useState, useMemo, useImperativeHandle } from 'react';
3
+ import React__default, { forwardRef as forwardRef$1, memo, useCallback, useState, useEffect, useMemo, useRef, useImperativeHandle } from 'react';
4
4
  import require$$1 from 'deepmerge';
5
+ import Animated, { useSharedValue, withSequence, withTiming, withSpring, useAnimatedStyle, interpolateColor, useAnimatedReaction } from 'react-native-reanimated';
5
6
  import color from 'color';
6
7
  import IconClose from './assets/svg/icon-close.svg';
7
8
  import IconCheckbox from './assets/svg/icon-checkbox.svg';
@@ -223,7 +224,8 @@ var yellow = {
223
224
  YELLOW_STATUS: YELLOW_STATUS,
224
225
  };
225
226
 
226
- var getWindowDimensions = function () { return Dimensions.get("window"); };
227
+ var DEVICE_HEIGHT = Dimensions.get("window").height;
228
+ var DEVICE_WIDTH = Dimensions.get("window").width;
227
229
  var ref = {
228
230
  palette: {
229
231
  dark: {
@@ -602,12 +604,8 @@ var typescale = {
602
604
  };
603
605
  var ThemeColors = ref.palette;
604
606
  var CONSTANTS = {
605
- get DEVICE_HEIGHT() {
606
- return getWindowDimensions().height;
607
- },
608
- get DEVICE_WIDTH() {
609
- return getWindowDimensions().width;
610
- },
607
+ DEVICE_HEIGHT: DEVICE_HEIGHT,
608
+ DEVICE_WIDTH: DEVICE_WIDTH,
611
609
  HEADER_HEIGHT: 50,
612
610
  BUTTON_HEIGHT: 48,
613
611
  BUTTON_HEIGHT_SMALL: 36,
@@ -1259,9 +1257,21 @@ var createTheming = _createTheming.default;
1259
1257
 
1260
1258
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1261
1259
 
1262
- var _a = createTheming(LightTheme); _a.ThemeProvider; _a.withTheme; var useAppTheme = _a.useTheme;
1260
+ var _a = createTheming(LightTheme); _a.ThemeProvider; _a.withTheme; _a.useTheme;
1263
1261
  var useInternalTheme = function () {
1264
- return useAppTheme();
1262
+ var colorScheme = useColorScheme();
1263
+ var isDark = colorScheme === "dark";
1264
+ var theme = getTheme(isDark);
1265
+ return theme;
1266
+ };
1267
+ var defaultThemesByVersion = {
1268
+ light: LightTheme,
1269
+ dark: DarkTheme,
1270
+ };
1271
+ var getTheme = function (isDark) {
1272
+ if (isDark === void 0) { isDark = false; }
1273
+ var scheme = isDark ? "dark" : "light";
1274
+ return defaultThemesByVersion[scheme];
1265
1275
  };
1266
1276
 
1267
1277
  var ViewCustom = forwardRef$1(function (_a, ref) {
@@ -1472,51 +1482,47 @@ var ViewCustom = forwardRef$1(function (_a, ref) {
1472
1482
  });
1473
1483
  var View = React__default.memo(ViewCustom);
1474
1484
 
1475
- var animateProgress = function (progress, toValue) {
1476
- Animated.sequence([
1477
- Animated.timing(progress, {
1478
- toValue: toValue,
1479
- duration: 150,
1480
- useNativeDriver: false,
1481
- }),
1482
- Animated.spring(progress, {
1483
- toValue: toValue,
1484
- damping: 20,
1485
- stiffness: 200,
1486
- mass: 0.5,
1487
- velocity: 0.5,
1488
- useNativeDriver: false,
1489
- }),
1490
- ]).start();
1491
- };
1492
1485
  var Switch = memo(function (_a) {
1493
1486
  var value = _a.value, disabled = _a.disabled, onValueChange = _a.onValueChange, _b = _a.size, size = _b === void 0 ? "normal" : _b;
1494
1487
  var theme = useInternalTheme();
1495
1488
  var colors = theme.colors;
1496
- var progress = useRef(new Animated.Value(value ? 1 : 0)).current;
1497
- useEffect(function () {
1498
- if (value !== undefined) {
1499
- animateProgress(progress, value ? 1 : 0);
1500
- }
1501
- }, [value, progress]);
1489
+ var progress = useSharedValue(value ? 1 : 0);
1502
1490
  var handleSwitch = useCallback(function () {
1503
1491
  if (disabled)
1504
1492
  return;
1505
1493
  var newValue = !value;
1506
- animateProgress(progress, newValue ? 1 : 0);
1494
+ progress.value = withSequence(withTiming(newValue ? 1 : 0, {
1495
+ duration: 150,
1496
+ }), withSpring(newValue ? 1 : 0, {
1497
+ damping: 20,
1498
+ stiffness: 200,
1499
+ mass: 0.5,
1500
+ velocity: 0.5,
1501
+ }));
1507
1502
  onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(newValue);
1508
- }, [disabled, value, onValueChange, progress]);
1509
- var translateX = progress.interpolate({
1510
- inputRange: [0, 1],
1511
- outputRange: [0, 20],
1503
+ }, [disabled, value, onValueChange]);
1504
+ var animatedStyle = useAnimatedStyle(function () {
1505
+ return {
1506
+ transform: [{ translateX: progress.value * 20 }],
1507
+ };
1512
1508
  });
1513
- var backgroundColor = progress.interpolate({
1514
- inputRange: [0, 1],
1515
- outputRange: [
1516
- colors.toggleBackgroundDefault,
1517
- colors.toggleBackgroundActive,
1518
- ],
1509
+ var backgroundColor = useAnimatedStyle(function () {
1510
+ return {
1511
+ backgroundColor: interpolateColor(progress.value, [0, 1], [colors.toggleBackgroundDefault, colors.toggleBackgroundActive]),
1512
+ };
1519
1513
  });
1514
+ useAnimatedReaction(function () { return value; }, function (currentValue) {
1515
+ if (currentValue !== undefined) {
1516
+ progress.value = withSequence(withTiming(currentValue ? 1 : 0, {
1517
+ duration: 150,
1518
+ }), withSpring(currentValue ? 1 : 0, {
1519
+ damping: 20,
1520
+ stiffness: 200,
1521
+ mass: 0.5,
1522
+ velocity: 0.5,
1523
+ }));
1524
+ }
1525
+ }, [value]);
1520
1526
  var getSizeSwitch = useCallback(function () {
1521
1527
  switch (size) {
1522
1528
  case "small":
@@ -1551,12 +1557,8 @@ var Switch = memo(function (_a) {
1551
1557
  }, [size, colors]);
1552
1558
  return (React$3.createElement(View, { row: true },
1553
1559
  React$3.createElement(TouchableOpacity, { activeOpacity: 1, onPress: handleSwitch, disabled: disabled, style: disabled ? { opacity: 0.6 } : {} },
1554
- React$3.createElement(Animated.View, { style: [styles$j.vSegment, { backgroundColor: backgroundColor }, getSizeSwitch()] },
1555
- React$3.createElement(Animated.View, { style: [
1556
- styles$j.animated,
1557
- { transform: [{ translateX: translateX }] },
1558
- getSizeCircle(),
1559
- ] })))));
1560
+ React$3.createElement(Animated.View, { style: [styles$j.vSegment, backgroundColor, getSizeSwitch()] },
1561
+ React$3.createElement(Animated.View, { style: [styles$j.animated, animatedStyle, getSizeCircle()] })))));
1560
1562
  });
1561
1563
  var styles$j = StyleSheet.create({
1562
1564
  vSegment: {
@@ -1567,6 +1569,11 @@ var styles$j = StyleSheet.create({
1567
1569
  },
1568
1570
  animated: {
1569
1571
  position: "absolute",
1572
+ // shadowColor: "#000000",
1573
+ // shadowOffset: { width: 0, height: 0 },
1574
+ // shadowOpacity: 0.15,
1575
+ // shadowRadius: BORDER_RADIUS_6,
1576
+ // elevation: 5,
1570
1577
  marginHorizontal: 2,
1571
1578
  },
1572
1579
  });
@@ -1928,7 +1935,7 @@ var TextInputAffix = function (_a) {
1928
1935
  _b);
1929
1936
  var textColor = getTextColor({ theme: theme, disabled: disabled });
1930
1937
  var content = (React__default.createElement(Text$2, { maxFontSizeMultiplier: maxFontSizeMultiplier, style: [{ color: textColor }, textStyle, labelStyle], onLayout: onTextLayout, testID: "".concat(testID, "-text") }, text));
1931
- return (React__default.createElement(Animated.View, { style: [
1938
+ return (React__default.createElement(Animated$1.View, { style: [
1932
1939
  styles$i.container,
1933
1940
  style,
1934
1941
  {
@@ -1996,7 +2003,7 @@ var AnimatedText = forwardRef(function AnimatedText(_a, ref) {
1996
2003
  if (typeof font !== "object") {
1997
2004
  throw new Error("Variant ".concat(variant, " was not provided properly. Valid variants are ").concat(Object.keys(theme.fonts).join(", "), "."));
1998
2005
  }
1999
- return (React$3.createElement(Animated.Text, __assign({ ref: ref }, rest, { style: [
2006
+ return (React$3.createElement(Animated$1.Text, __assign({ ref: ref }, rest, { style: [
2000
2007
  font,
2001
2008
  styles$h.text,
2002
2009
  { writingDirection: writingDirection, color: theme.colors.backgroundPrimary },
@@ -4593,7 +4600,7 @@ var InputLabel = function (props) {
4593
4600
  // Position colored placeholder and gray placeholder on top of each other and crossfade them
4594
4601
  // This gives the effect of animating the color, but allows us to use native driver
4595
4602
  React__default.createElement(View$1, { pointerEvents: "none", style: [StyleSheet.absoluteFill, styles$g.overflow, styles$g.labelContainer] },
4596
- React__default.createElement(Animated.View, { pointerEvents: "none", style: [
4603
+ React__default.createElement(Animated$1.View, { pointerEvents: "none", style: [
4597
4604
  StyleSheet.absoluteFill,
4598
4605
  Platform.OS !== "web" && { width: width },
4599
4606
  { opacity: opacity },
@@ -4677,6 +4684,8 @@ var Spacer = function (_a) {
4677
4684
  return (React__default.createElement(View, { backgroundColor: backgroundColor || "transparent", width: width, height: height, style: [style] }));
4678
4685
  };
4679
4686
 
4687
+ Dimensions.get("window").height;
4688
+ Dimensions.get("window").width;
4680
4689
  var BUTTON_HEIGHT = 48;
4681
4690
  var BUTTON_HEIGHT_SMALL = 40;
4682
4691
  var SPACE_4 = 4;
@@ -4853,8 +4862,8 @@ var TextInputFlat = function (_a) {
4853
4862
  adjustPaddingFlat(__assign(__assign({}, paddingSettings), { pad: pad }));
4854
4863
  var baseLabelTranslateY = -labelHalfHeight - (topPosition + MINIMIZED_LABEL_Y_OFFSET);
4855
4864
  var placeholderOpacityAnims = React$3.useRef([
4856
- new Animated.Value(0),
4857
- new Animated.Value(1),
4865
+ new Animated$1.Value(0),
4866
+ new Animated$1.Value(1),
4858
4867
  ]).current;
4859
4868
  var placeholderOpacity = hasActiveOutline
4860
4869
  ? parentState.labeled
@@ -5923,8 +5932,8 @@ var TextInput = forwardRef(function (_a, ref) {
5923
5932
  var theme = useInternalTheme();
5924
5933
  var isControlled = rest.value !== undefined;
5925
5934
  var validInputValue = isControlled ? rest.value : rest.defaultValue;
5926
- var labeled = React__default.useRef(new Animated.Value(validInputValue ? 0 : 1)).current;
5927
- var error = React__default.useRef(new Animated.Value(errorProp ? 1 : 0)).current;
5935
+ var labeled = React__default.useRef(new Animated$1.Value(validInputValue ? 0 : 1)).current;
5936
+ var error = React__default.useRef(new Animated$1.Value(errorProp ? 1 : 0)).current;
5928
5937
  var _k = React__default.useState(false), focused = _k[0], setFocused = _k[1];
5929
5938
  var _l = React__default.useState(false), displayPlaceholder = _l[0], setDisplayPlaceholder = _l[1];
5930
5939
  var _m = React__default.useState(validInputValue), uncontrolledValue = _m[0], setUncontrolledValue = _m[1];
@@ -5964,7 +5973,7 @@ var TextInput = forwardRef(function (_a, ref) {
5964
5973
  // When the input has an error, we wiggle the label and apply error styles
5965
5974
  if (errorProp) {
5966
5975
  // show error
5967
- Animated.timing(error, {
5976
+ Animated$1.timing(error, {
5968
5977
  toValue: 1,
5969
5978
  duration: FOCUS_ANIMATION_DURATION * scale,
5970
5979
  // To prevent this - https://github.com/callstack/react-native-paper/issues/941
@@ -5974,7 +5983,7 @@ var TextInput = forwardRef(function (_a, ref) {
5974
5983
  else {
5975
5984
  // hide error
5976
5985
  {
5977
- Animated.timing(error, {
5986
+ Animated$1.timing(error, {
5978
5987
  toValue: 0,
5979
5988
  duration: BLUR_ANIMATION_DURATION * scale,
5980
5989
  // To prevent this - https://github.com/callstack/react-native-paper/issues/941
@@ -6014,7 +6023,7 @@ var TextInput = forwardRef(function (_a, ref) {
6014
6023
  // https://github.com/callstack/react-native-paper/pull/1440
6015
6024
  if (value || focused) {
6016
6025
  // minimize label
6017
- Animated.timing(labeled, {
6026
+ Animated$1.timing(labeled, {
6018
6027
  toValue: 0,
6019
6028
  duration: BLUR_ANIMATION_DURATION * scale,
6020
6029
  // To prevent this - https://github.com/callstack/react-native-paper/issues/941
@@ -6023,7 +6032,7 @@ var TextInput = forwardRef(function (_a, ref) {
6023
6032
  }
6024
6033
  else {
6025
6034
  // restore label
6026
- Animated.timing(labeled, {
6035
+ Animated$1.timing(labeled, {
6027
6036
  toValue: 1,
6028
6037
  duration: FOCUS_ANIMATION_DURATION * scale,
6029
6038
  // To prevent this - https://github.com/callstack/react-native-paper/issues/941
@@ -6338,9 +6347,9 @@ var ViewVisibleAnimated = React__default.memo(React__default.forwardRef(function
6338
6347
  hide: hide,
6339
6348
  show: show,
6340
6349
  }); });
6341
- var visibleAnimation = useRef(new Animated.Value(0)).current;
6342
- var translateAnimation = useRef(new Animated.Value(0)).current;
6343
- var scaleAnimation = useRef(new Animated.Value(scaleType === "in" ? 0 : 3)).current;
6350
+ var visibleAnimation = useRef(new Animated$1.Value(0)).current;
6351
+ var translateAnimation = useRef(new Animated$1.Value(0)).current;
6352
+ var scaleAnimation = useRef(new Animated$1.Value(scaleType === "in" ? 0 : 3)).current;
6344
6353
  var _o = useState(false), visible = _o[0], setVisible = _o[1];
6345
6354
  var TIME_OUT = null;
6346
6355
  useEffect(function () {
@@ -6371,18 +6380,18 @@ var ViewVisibleAnimated = React__default.memo(React__default.forwardRef(function
6371
6380
  if (position === void 0) { position = "bottom"; }
6372
6381
  setVisible(true);
6373
6382
  translateAnimation.setValue(position === "bottom" ? 100 : -100);
6374
- Animated.parallel([
6375
- Animated.timing(scaleAnimation, {
6383
+ Animated$1.parallel([
6384
+ Animated$1.timing(scaleAnimation, {
6376
6385
  toValue: 1,
6377
6386
  duration: duration,
6378
6387
  useNativeDriver: true,
6379
6388
  }),
6380
- Animated.timing(visibleAnimation, {
6389
+ Animated$1.timing(visibleAnimation, {
6381
6390
  toValue: 1,
6382
6391
  duration: duration,
6383
6392
  useNativeDriver: true,
6384
6393
  }),
6385
- Animated.timing(translateAnimation, {
6394
+ Animated$1.timing(translateAnimation, {
6386
6395
  toValue: 0,
6387
6396
  duration: duration,
6388
6397
  useNativeDriver: true,
@@ -6403,18 +6412,18 @@ var ViewVisibleAnimated = React__default.memo(React__default.forwardRef(function
6403
6412
  };
6404
6413
  var handleHide = function (_a) {
6405
6414
  var durationHide = _a.durationHide, callback = _a.callback, _b = _a.position, position = _b === void 0 ? "bottom" : _b;
6406
- Animated.parallel([
6407
- Animated.timing(scaleAnimation, {
6415
+ Animated$1.parallel([
6416
+ Animated$1.timing(scaleAnimation, {
6408
6417
  toValue: scaleType === "in" ? 0 : 3,
6409
6418
  duration: durationHide,
6410
6419
  useNativeDriver: true,
6411
6420
  }),
6412
- Animated.timing(visibleAnimation, {
6421
+ Animated$1.timing(visibleAnimation, {
6413
6422
  toValue: 0,
6414
6423
  duration: durationHide,
6415
6424
  useNativeDriver: true,
6416
6425
  }),
6417
- Animated.timing(translateAnimation, {
6426
+ Animated$1.timing(translateAnimation, {
6418
6427
  toValue: position === "bottom" ? 300 : -300,
6419
6428
  duration: durationHide,
6420
6429
  useNativeDriver: true,
@@ -6424,7 +6433,7 @@ var ViewVisibleAnimated = React__default.memo(React__default.forwardRef(function
6424
6433
  callback === null || callback === void 0 ? void 0 : callback();
6425
6434
  });
6426
6435
  };
6427
- return (React__default.createElement(Animated.View, { style: [
6436
+ return (React__default.createElement(Animated$1.View, { style: [
6428
6437
  style,
6429
6438
  {
6430
6439
  opacity: visibleAnimation,
@@ -6616,7 +6625,14 @@ var styles$9 = StyleSheet.create({
6616
6625
  },
6617
6626
  });
6618
6627
 
6619
- var IMAGE_DEFAULT = require('./image_default.png');
6628
+ /* eslint-disable @typescript-eslint/no-var-requires */
6629
+ var imageDefault;
6630
+ var getImageDefault = function () {
6631
+ if (imageDefault === undefined) {
6632
+ imageDefault = require("./image_default.png");
6633
+ }
6634
+ return imageDefault;
6635
+ };
6620
6636
 
6621
6637
  var getSource = function (source) {
6622
6638
  var newSource = source;
@@ -6633,8 +6649,8 @@ var Image = function (props) {
6633
6649
  var image = getSource(disableDefaultImage
6634
6650
  ? source
6635
6651
  : hasError
6636
- ? IMAGE_DEFAULT
6637
- : source || IMAGE_DEFAULT);
6652
+ ? getImageDefault()
6653
+ : source || getImageDefault());
6638
6654
  var ImageComponent = children ? ImageBackground : Image$2;
6639
6655
  // const getUriImage = (uri: string) => {
6640
6656
  // return uri !== null &&
@@ -7648,7 +7664,7 @@ var showToast = function (_a) {
7648
7664
  };
7649
7665
 
7650
7666
  var ToastProvider = forwardRef$1(function (_a, ref) {
7651
- var children = _a.children, _b = _a.wrapSafeArea, wrapSafeArea = _b === void 0 ? false : _b;
7667
+ var children = _a.children, _b = _a.wrapSafeArea, wrapSafeArea = _b === void 0 ? true : _b;
7652
7668
  var toastComponentRef = React__default.useRef(null);
7653
7669
  // Expose the show method through the ref
7654
7670
  useImperativeHandle(ref, function () { return ({