sapo-components-ui-rn 1.1.84 → 1.1.86
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 +2 -3
- package/dist/index.esm.js +65 -63
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +40 -39
- package/dist/index.js.map +1 -1
- package/package.json +1 -4
- package/src/components/Switch/Switch.tsx +44 -64
package/README.md
CHANGED
|
@@ -19,10 +19,9 @@ 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": "*",
|
|
24
22
|
"react-native-safe-area-context": "*",
|
|
25
|
-
"react-native-screens": "*"
|
|
23
|
+
"react-native-screens": "*",
|
|
24
|
+
"react-native-svg": "*"
|
|
26
25
|
}
|
|
27
26
|
```
|
|
28
27
|
|
package/dist/index.esm.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { Dimensions, Platform, StyleSheet, useColorScheme, TouchableOpacity, View as View$1, Text as Text$2,
|
|
1
|
+
import { Dimensions, Platform, StyleSheet, useColorScheme, 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';
|
|
2
2
|
import * as React$3 from 'react';
|
|
3
|
-
import React__default, { forwardRef as forwardRef$1, memo,
|
|
3
|
+
import React__default, { forwardRef as forwardRef$1, memo, useRef, useEffect, useCallback, useState, useMemo, useImperativeHandle } from 'react';
|
|
4
4
|
import require$$1 from 'deepmerge';
|
|
5
|
-
import Animated, { useSharedValue, withSequence, withTiming, withSpring, useAnimatedStyle, interpolateColor, useAnimatedReaction } from 'react-native-reanimated';
|
|
6
5
|
import color from 'color';
|
|
7
6
|
import IconClose from './assets/svg/icon-close.svg';
|
|
8
7
|
import IconCheckbox from './assets/svg/icon-checkbox.svg';
|
|
@@ -1530,47 +1529,51 @@ var ViewCustom = forwardRef$1(function (_a, ref) {
|
|
|
1530
1529
|
});
|
|
1531
1530
|
var View = React__default.memo(ViewCustom);
|
|
1532
1531
|
|
|
1532
|
+
var animateProgress = function (progress, toValue) {
|
|
1533
|
+
Animated.sequence([
|
|
1534
|
+
Animated.timing(progress, {
|
|
1535
|
+
toValue: toValue,
|
|
1536
|
+
duration: 150,
|
|
1537
|
+
useNativeDriver: false,
|
|
1538
|
+
}),
|
|
1539
|
+
Animated.spring(progress, {
|
|
1540
|
+
toValue: toValue,
|
|
1541
|
+
damping: 20,
|
|
1542
|
+
stiffness: 200,
|
|
1543
|
+
mass: 0.5,
|
|
1544
|
+
velocity: 0.5,
|
|
1545
|
+
useNativeDriver: false,
|
|
1546
|
+
}),
|
|
1547
|
+
]).start();
|
|
1548
|
+
};
|
|
1533
1549
|
var Switch = memo(function (_a) {
|
|
1534
1550
|
var value = _a.value, disabled = _a.disabled, onValueChange = _a.onValueChange, _b = _a.size, size = _b === void 0 ? "normal" : _b;
|
|
1535
1551
|
var theme = useInternalTheme();
|
|
1536
1552
|
var colors = theme.colors;
|
|
1537
|
-
var progress =
|
|
1553
|
+
var progress = useRef(new Animated.Value(value ? 1 : 0)).current;
|
|
1554
|
+
useEffect(function () {
|
|
1555
|
+
if (value !== undefined) {
|
|
1556
|
+
animateProgress(progress, value ? 1 : 0);
|
|
1557
|
+
}
|
|
1558
|
+
}, [value, progress]);
|
|
1538
1559
|
var handleSwitch = useCallback(function () {
|
|
1539
1560
|
if (disabled)
|
|
1540
1561
|
return;
|
|
1541
1562
|
var newValue = !value;
|
|
1542
|
-
progress
|
|
1543
|
-
duration: 150,
|
|
1544
|
-
}), withSpring(newValue ? 1 : 0, {
|
|
1545
|
-
damping: 20,
|
|
1546
|
-
stiffness: 200,
|
|
1547
|
-
mass: 0.5,
|
|
1548
|
-
velocity: 0.5,
|
|
1549
|
-
}));
|
|
1563
|
+
animateProgress(progress, newValue ? 1 : 0);
|
|
1550
1564
|
onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(newValue);
|
|
1551
|
-
}, [disabled, value, onValueChange]);
|
|
1552
|
-
var
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
};
|
|
1565
|
+
}, [disabled, value, onValueChange, progress]);
|
|
1566
|
+
var translateX = progress.interpolate({
|
|
1567
|
+
inputRange: [0, 1],
|
|
1568
|
+
outputRange: [0, 20],
|
|
1556
1569
|
});
|
|
1557
|
-
var backgroundColor =
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1570
|
+
var backgroundColor = progress.interpolate({
|
|
1571
|
+
inputRange: [0, 1],
|
|
1572
|
+
outputRange: [
|
|
1573
|
+
colors.toggleBackgroundDefault,
|
|
1574
|
+
colors.toggleBackgroundActive,
|
|
1575
|
+
],
|
|
1561
1576
|
});
|
|
1562
|
-
useAnimatedReaction(function () { return value; }, function (currentValue) {
|
|
1563
|
-
if (currentValue !== undefined) {
|
|
1564
|
-
progress.value = withSequence(withTiming(currentValue ? 1 : 0, {
|
|
1565
|
-
duration: 150,
|
|
1566
|
-
}), withSpring(currentValue ? 1 : 0, {
|
|
1567
|
-
damping: 20,
|
|
1568
|
-
stiffness: 200,
|
|
1569
|
-
mass: 0.5,
|
|
1570
|
-
velocity: 0.5,
|
|
1571
|
-
}));
|
|
1572
|
-
}
|
|
1573
|
-
}, [value]);
|
|
1574
1577
|
var getSizeSwitch = useCallback(function () {
|
|
1575
1578
|
switch (size) {
|
|
1576
1579
|
case "small":
|
|
@@ -1605,8 +1608,12 @@ var Switch = memo(function (_a) {
|
|
|
1605
1608
|
}, [size, colors]);
|
|
1606
1609
|
return (React$3.createElement(View, { row: true },
|
|
1607
1610
|
React$3.createElement(TouchableOpacity, { activeOpacity: 1, onPress: handleSwitch, disabled: disabled, style: disabled ? { opacity: 0.6 } : {} },
|
|
1608
|
-
React$3.createElement(Animated.View, { style: [styles$j.vSegment, backgroundColor, getSizeSwitch()] },
|
|
1609
|
-
React$3.createElement(Animated.View, { style: [
|
|
1611
|
+
React$3.createElement(Animated.View, { style: [styles$j.vSegment, { backgroundColor: backgroundColor }, getSizeSwitch()] },
|
|
1612
|
+
React$3.createElement(Animated.View, { style: [
|
|
1613
|
+
styles$j.animated,
|
|
1614
|
+
{ transform: [{ translateX: translateX }] },
|
|
1615
|
+
getSizeCircle(),
|
|
1616
|
+
] })))));
|
|
1610
1617
|
});
|
|
1611
1618
|
var styles$j = StyleSheet.create({
|
|
1612
1619
|
vSegment: {
|
|
@@ -1617,11 +1624,6 @@ var styles$j = StyleSheet.create({
|
|
|
1617
1624
|
},
|
|
1618
1625
|
animated: {
|
|
1619
1626
|
position: "absolute",
|
|
1620
|
-
// shadowColor: "#000000",
|
|
1621
|
-
// shadowOffset: { width: 0, height: 0 },
|
|
1622
|
-
// shadowOpacity: 0.15,
|
|
1623
|
-
// shadowRadius: BORDER_RADIUS_6,
|
|
1624
|
-
// elevation: 5,
|
|
1625
1627
|
marginHorizontal: 2,
|
|
1626
1628
|
},
|
|
1627
1629
|
});
|
|
@@ -1983,7 +1985,7 @@ var TextInputAffix = function (_a) {
|
|
|
1983
1985
|
_b);
|
|
1984
1986
|
var textColor = getTextColor({ theme: theme, disabled: disabled });
|
|
1985
1987
|
var content = (React__default.createElement(Text$2, { maxFontSizeMultiplier: maxFontSizeMultiplier, style: [{ color: textColor }, textStyle, labelStyle], onLayout: onTextLayout, testID: "".concat(testID, "-text") }, text));
|
|
1986
|
-
return (React__default.createElement(Animated
|
|
1988
|
+
return (React__default.createElement(Animated.View, { style: [
|
|
1987
1989
|
styles$i.container,
|
|
1988
1990
|
style,
|
|
1989
1991
|
{
|
|
@@ -2051,7 +2053,7 @@ var AnimatedText = forwardRef(function AnimatedText(_a, ref) {
|
|
|
2051
2053
|
if (typeof font !== "object") {
|
|
2052
2054
|
throw new Error("Variant ".concat(variant, " was not provided properly. Valid variants are ").concat(Object.keys(theme.fonts).join(", "), "."));
|
|
2053
2055
|
}
|
|
2054
|
-
return (React$3.createElement(Animated
|
|
2056
|
+
return (React$3.createElement(Animated.Text, __assign({ ref: ref }, rest, { style: [
|
|
2055
2057
|
font,
|
|
2056
2058
|
styles$h.text,
|
|
2057
2059
|
{ writingDirection: writingDirection, color: theme.colors.backgroundPrimary },
|
|
@@ -4648,7 +4650,7 @@ var InputLabel = function (props) {
|
|
|
4648
4650
|
// Position colored placeholder and gray placeholder on top of each other and crossfade them
|
|
4649
4651
|
// This gives the effect of animating the color, but allows us to use native driver
|
|
4650
4652
|
React__default.createElement(View$1, { pointerEvents: "none", style: [StyleSheet.absoluteFill, styles$g.overflow, styles$g.labelContainer] },
|
|
4651
|
-
React__default.createElement(Animated
|
|
4653
|
+
React__default.createElement(Animated.View, { pointerEvents: "none", style: [
|
|
4652
4654
|
StyleSheet.absoluteFill,
|
|
4653
4655
|
Platform.OS !== "web" && { width: width },
|
|
4654
4656
|
{ opacity: opacity },
|
|
@@ -4910,8 +4912,8 @@ var TextInputFlat = function (_a) {
|
|
|
4910
4912
|
adjustPaddingFlat(__assign(__assign({}, paddingSettings), { pad: pad }));
|
|
4911
4913
|
var baseLabelTranslateY = -labelHalfHeight - (topPosition + MINIMIZED_LABEL_Y_OFFSET);
|
|
4912
4914
|
var placeholderOpacityAnims = React$3.useRef([
|
|
4913
|
-
new Animated
|
|
4914
|
-
new Animated
|
|
4915
|
+
new Animated.Value(0),
|
|
4916
|
+
new Animated.Value(1),
|
|
4915
4917
|
]).current;
|
|
4916
4918
|
var placeholderOpacity = hasActiveOutline
|
|
4917
4919
|
? parentState.labeled
|
|
@@ -5980,8 +5982,8 @@ var TextInput = forwardRef(function (_a, ref) {
|
|
|
5980
5982
|
var theme = useInternalTheme();
|
|
5981
5983
|
var isControlled = rest.value !== undefined;
|
|
5982
5984
|
var validInputValue = isControlled ? rest.value : rest.defaultValue;
|
|
5983
|
-
var labeled = React__default.useRef(new Animated
|
|
5984
|
-
var error = React__default.useRef(new Animated
|
|
5985
|
+
var labeled = React__default.useRef(new Animated.Value(validInputValue ? 0 : 1)).current;
|
|
5986
|
+
var error = React__default.useRef(new Animated.Value(errorProp ? 1 : 0)).current;
|
|
5985
5987
|
var _k = React__default.useState(false), focused = _k[0], setFocused = _k[1];
|
|
5986
5988
|
var _l = React__default.useState(false), displayPlaceholder = _l[0], setDisplayPlaceholder = _l[1];
|
|
5987
5989
|
var _m = React__default.useState(validInputValue), uncontrolledValue = _m[0], setUncontrolledValue = _m[1];
|
|
@@ -6021,7 +6023,7 @@ var TextInput = forwardRef(function (_a, ref) {
|
|
|
6021
6023
|
// When the input has an error, we wiggle the label and apply error styles
|
|
6022
6024
|
if (errorProp) {
|
|
6023
6025
|
// show error
|
|
6024
|
-
Animated
|
|
6026
|
+
Animated.timing(error, {
|
|
6025
6027
|
toValue: 1,
|
|
6026
6028
|
duration: FOCUS_ANIMATION_DURATION * scale,
|
|
6027
6029
|
// To prevent this - https://github.com/callstack/react-native-paper/issues/941
|
|
@@ -6031,7 +6033,7 @@ var TextInput = forwardRef(function (_a, ref) {
|
|
|
6031
6033
|
else {
|
|
6032
6034
|
// hide error
|
|
6033
6035
|
{
|
|
6034
|
-
Animated
|
|
6036
|
+
Animated.timing(error, {
|
|
6035
6037
|
toValue: 0,
|
|
6036
6038
|
duration: BLUR_ANIMATION_DURATION * scale,
|
|
6037
6039
|
// To prevent this - https://github.com/callstack/react-native-paper/issues/941
|
|
@@ -6071,7 +6073,7 @@ var TextInput = forwardRef(function (_a, ref) {
|
|
|
6071
6073
|
// https://github.com/callstack/react-native-paper/pull/1440
|
|
6072
6074
|
if (value || focused) {
|
|
6073
6075
|
// minimize label
|
|
6074
|
-
Animated
|
|
6076
|
+
Animated.timing(labeled, {
|
|
6075
6077
|
toValue: 0,
|
|
6076
6078
|
duration: BLUR_ANIMATION_DURATION * scale,
|
|
6077
6079
|
// To prevent this - https://github.com/callstack/react-native-paper/issues/941
|
|
@@ -6080,7 +6082,7 @@ var TextInput = forwardRef(function (_a, ref) {
|
|
|
6080
6082
|
}
|
|
6081
6083
|
else {
|
|
6082
6084
|
// restore label
|
|
6083
|
-
Animated
|
|
6085
|
+
Animated.timing(labeled, {
|
|
6084
6086
|
toValue: 1,
|
|
6085
6087
|
duration: FOCUS_ANIMATION_DURATION * scale,
|
|
6086
6088
|
// To prevent this - https://github.com/callstack/react-native-paper/issues/941
|
|
@@ -6395,9 +6397,9 @@ var ViewVisibleAnimated = React__default.memo(React__default.forwardRef(function
|
|
|
6395
6397
|
hide: hide,
|
|
6396
6398
|
show: show,
|
|
6397
6399
|
}); });
|
|
6398
|
-
var visibleAnimation = useRef(new Animated
|
|
6399
|
-
var translateAnimation = useRef(new Animated
|
|
6400
|
-
var scaleAnimation = useRef(new Animated
|
|
6400
|
+
var visibleAnimation = useRef(new Animated.Value(0)).current;
|
|
6401
|
+
var translateAnimation = useRef(new Animated.Value(0)).current;
|
|
6402
|
+
var scaleAnimation = useRef(new Animated.Value(scaleType === "in" ? 0 : 3)).current;
|
|
6401
6403
|
var _o = useState(false), visible = _o[0], setVisible = _o[1];
|
|
6402
6404
|
var TIME_OUT = null;
|
|
6403
6405
|
useEffect(function () {
|
|
@@ -6428,18 +6430,18 @@ var ViewVisibleAnimated = React__default.memo(React__default.forwardRef(function
|
|
|
6428
6430
|
if (position === void 0) { position = "bottom"; }
|
|
6429
6431
|
setVisible(true);
|
|
6430
6432
|
translateAnimation.setValue(position === "bottom" ? 100 : -100);
|
|
6431
|
-
Animated
|
|
6432
|
-
Animated
|
|
6433
|
+
Animated.parallel([
|
|
6434
|
+
Animated.timing(scaleAnimation, {
|
|
6433
6435
|
toValue: 1,
|
|
6434
6436
|
duration: duration,
|
|
6435
6437
|
useNativeDriver: true,
|
|
6436
6438
|
}),
|
|
6437
|
-
Animated
|
|
6439
|
+
Animated.timing(visibleAnimation, {
|
|
6438
6440
|
toValue: 1,
|
|
6439
6441
|
duration: duration,
|
|
6440
6442
|
useNativeDriver: true,
|
|
6441
6443
|
}),
|
|
6442
|
-
Animated
|
|
6444
|
+
Animated.timing(translateAnimation, {
|
|
6443
6445
|
toValue: 0,
|
|
6444
6446
|
duration: duration,
|
|
6445
6447
|
useNativeDriver: true,
|
|
@@ -6460,18 +6462,18 @@ var ViewVisibleAnimated = React__default.memo(React__default.forwardRef(function
|
|
|
6460
6462
|
};
|
|
6461
6463
|
var handleHide = function (_a) {
|
|
6462
6464
|
var durationHide = _a.durationHide, callback = _a.callback, _b = _a.position, position = _b === void 0 ? "bottom" : _b;
|
|
6463
|
-
Animated
|
|
6464
|
-
Animated
|
|
6465
|
+
Animated.parallel([
|
|
6466
|
+
Animated.timing(scaleAnimation, {
|
|
6465
6467
|
toValue: scaleType === "in" ? 0 : 3,
|
|
6466
6468
|
duration: durationHide,
|
|
6467
6469
|
useNativeDriver: true,
|
|
6468
6470
|
}),
|
|
6469
|
-
Animated
|
|
6471
|
+
Animated.timing(visibleAnimation, {
|
|
6470
6472
|
toValue: 0,
|
|
6471
6473
|
duration: durationHide,
|
|
6472
6474
|
useNativeDriver: true,
|
|
6473
6475
|
}),
|
|
6474
|
-
Animated
|
|
6476
|
+
Animated.timing(translateAnimation, {
|
|
6475
6477
|
toValue: position === "bottom" ? 300 : -300,
|
|
6476
6478
|
duration: durationHide,
|
|
6477
6479
|
useNativeDriver: true,
|
|
@@ -6481,7 +6483,7 @@ var ViewVisibleAnimated = React__default.memo(React__default.forwardRef(function
|
|
|
6481
6483
|
callback === null || callback === void 0 ? void 0 : callback();
|
|
6482
6484
|
});
|
|
6483
6485
|
};
|
|
6484
|
-
return (React__default.createElement(Animated
|
|
6486
|
+
return (React__default.createElement(Animated.View, { style: [
|
|
6485
6487
|
style,
|
|
6486
6488
|
{
|
|
6487
6489
|
opacity: visibleAnimation,
|