diff --git a/.changeset/large-bulldogs-pull.md b/.changeset/large-bulldogs-pull.md new file mode 100644 index 0000000000..b89be44992 --- /dev/null +++ b/.changeset/large-bulldogs-pull.md @@ -0,0 +1,6 @@ +--- +'@td-design/react-native-picker': patch +'@td-design/react-native': patch +--- + +修复一些bug diff --git a/packages/react-native-picker/src/components/DatePicker/index.tsx b/packages/react-native-picker/src/components/DatePicker/index.tsx index 630c9f4c54..4ce8d1c054 100644 --- a/packages/react-native-picker/src/components/DatePicker/index.tsx +++ b/packages/react-native-picker/src/components/DatePicker/index.tsx @@ -23,22 +23,21 @@ const DatePicker: FC< const { values, cols } = getValueCols(); - /** 生成日期picker */ - const renderDateTimePicker = () => { - return cols.map((col, index) => { - return ( - onValueChange(itemValue, index)} - /> - ); - }); - }; - - return {renderDateTimePicker()}; + return ( + + {cols.map((col, index) => { + return ( + onValueChange(itemValue, index)} + /> + ); + })} + + ); }; export default React.memo(DatePicker, (p, n) => { diff --git a/packages/react-native-picker/src/components/WheelPicker/WheelPickerItem.tsx b/packages/react-native-picker/src/components/WheelPicker/WheelPickerItem.tsx index 2c92c397df..d562361d6c 100644 --- a/packages/react-native-picker/src/components/WheelPicker/WheelPickerItem.tsx +++ b/packages/react-native-picker/src/components/WheelPicker/WheelPickerItem.tsx @@ -1,13 +1,13 @@ import React, { memo } from 'react'; import { Animated, StyleSheet } from 'react-native'; -import { WhellPickerItemProps } from './type'; +import { WheelPickerItemProps } from './type'; const opacityFunction = (val: number) => 1 / (1 + Math.abs(val)); const scaleFunction = (val: number) => 1 - 0.1 * Math.abs(val); const rotationFunction = (val: number) => 20 * val; -function WheelPickerItem({ textStyle, style, visibleRest, height, option, index, currentIndex }: WhellPickerItemProps) { +function WheelPickerItem({ textStyle, style, visibleRest, height, option, index, currentIndex }: WheelPickerItemProps) { const relativeScrollIndex = Animated.subtract(index, currentIndex); const inputRange = [0]; diff --git a/packages/react-native-picker/src/components/WheelPicker/index.tsx b/packages/react-native-picker/src/components/WheelPicker/index.tsx index ff0b52877a..564c727fa2 100644 --- a/packages/react-native-picker/src/components/WheelPicker/index.tsx +++ b/packages/react-native-picker/src/components/WheelPicker/index.tsx @@ -94,6 +94,21 @@ export default function WheelPicker({ }, }); + const renderItem = useCallback( + ({ item: option, index }) => ( + + ), + [itemStyle, itemTextStyle, itemHeight, currentScrollIndex] + ); + return ( @@ -116,17 +131,7 @@ export default function WheelPicker({ })} data={paddedOptions} keyExtractor={(_, index) => index.toString()} - renderItem={({ item: option, index }) => ( - - )} + renderItem={renderItem} /> ); diff --git a/packages/react-native-picker/src/components/WheelPicker/type.ts b/packages/react-native-picker/src/components/WheelPicker/type.ts index bde2f4d214..9239513b6d 100644 --- a/packages/react-native-picker/src/components/WheelPicker/type.ts +++ b/packages/react-native-picker/src/components/WheelPicker/type.ts @@ -34,7 +34,7 @@ export interface WheelPickerProps extends WheelPickerPropsBase { } /** 滚轮选择器子项的属性 */ -export interface WhellPickerItemProps { +export interface WheelPickerItemProps { textStyle: StyleProp; style: StyleProp; option: OptionItem | null; diff --git a/packages/react-native-picker/src/date-period-input/index.tsx b/packages/react-native-picker/src/date-period-input/index.tsx index a0731e2755..afd04ef29e 100644 --- a/packages/react-native-picker/src/date-period-input/index.tsx +++ b/packages/react-native-picker/src/date-period-input/index.tsx @@ -1,6 +1,5 @@ import React, { FC, ReactNode } from 'react'; import { StyleSheet } from 'react-native'; -import Animated, { FadeInRight, FadeOutRight } from 'react-native-reanimated'; import { Box, Flex, helpers, Pressable, SvgIcon, Text, useTheme } from '@td-design/react-native'; import { useSafeState } from '@td-design/rn-hooks'; @@ -25,7 +24,6 @@ export interface DatePeriodInputProps disabled?: boolean; } -const AnimatedTouchableIcon = Animated.createAnimatedComponent(Pressable); const { ONE_PIXEL } = helpers; /** 适用于筛选条件下的日期区间选择 */ @@ -70,23 +68,7 @@ const DatePeriodInput: FC = ({ icon: { alignItems: 'flex-end' }, }); - const renderLabel = () => { - if (!!label) - return ( - - {typeof label === 'string' ? ( - - {label} - - ) : ( - label - )} - - ); - return null; - }; - - const renderContent1 = () => ( + const BaseContent1 = ( <> @@ -95,20 +77,14 @@ const DatePeriodInput: FC = ({ {!disabled && allowClear && dates[0] && ( - + - + )} ); - const renderContent2 = () => ( + const BaseContent2 = ( <> @@ -117,38 +93,32 @@ const DatePeriodInput: FC = ({ {!disabled && allowClear && dates[1] && ( - + - + )} ); const Content1 = disabled ? ( - {renderContent1()} + {BaseContent1} ) : ( - {renderContent1()} + {BaseContent1} ); const Content2 = disabled ? ( - {renderContent2()} + {BaseContent2} ) : ( - {renderContent2()} + {BaseContent2} ); return ( - {renderLabel()} + {allowClear && editable && !!inputValue && ( - + - + )} {inputType === 'password' && ( diff --git a/packages/react-native/src/input/index.tsx b/packages/react-native/src/input/index.tsx index 1b92586340..c7ae3d6703 100644 --- a/packages/react-native/src/input/index.tsx +++ b/packages/react-native/src/input/index.tsx @@ -1,6 +1,5 @@ import React, { forwardRef, memo, ReactNode } from 'react'; import { StyleProp, StyleSheet, TextInput, TextInputProps, TextStyle } from 'react-native'; -import Animated, { FadeInRight, FadeOutRight } from 'react-native-reanimated'; import { useTheme } from '@shopify/restyle'; @@ -15,7 +14,6 @@ import InputItem from './InputItem'; import TextArea from './TextArea'; import useInput from './useInput'; -const AnimatedTouchableIcon = Animated.createAnimatedComponent(Pressable); const { ONE_PIXEL, px } = helpers; export interface InputProps extends Omit { /** 标签 */ @@ -124,15 +122,9 @@ const Input = forwardRef( /> {allowClear && !disabled && !!inputValue && ( - + - + )} {inputType === 'password' && ( @@ -175,7 +167,7 @@ const Label = memo(({ colon, label, required }: Pick {required && *} - {colon ? ':' : ''} @@ -184,7 +176,7 @@ const Label = memo(({ colon, label, required }: Pick {required && *} - {allowClear && !disabled && !!currentText && currentText !== placeholder && ( - + - + )} {!!extra && ( diff --git a/packages/react-native/src/number-keyboard/NumberKeyboardItem.tsx b/packages/react-native/src/number-keyboard/NumberKeyboardItem.tsx index bc270f8097..682e93a8c5 100644 --- a/packages/react-native/src/number-keyboard/NumberKeyboardItem.tsx +++ b/packages/react-native/src/number-keyboard/NumberKeyboardItem.tsx @@ -1,6 +1,5 @@ import React, { forwardRef } from 'react'; import { Keyboard, StyleSheet } from 'react-native'; -import Animated, { FadeInRight, FadeOutRight } from 'react-native-reanimated'; import { useTheme } from '@shopify/restyle'; @@ -15,7 +14,6 @@ import NumberKeyboardModal from './NumberKeyboardModal'; import { NumberKeyboardItemProps, NumberKeyboardRef } from './type'; import useNumberKeyboard from './useNumberKeyboard'; -const AnimatedTouchableIcon = Animated.createAnimatedComponent(Pressable); const { px } = helpers; const NumberKeyboardItem = forwardRef( ( @@ -80,15 +78,9 @@ const NumberKeyboardItem = forwardRef {allowClear && !disabled && !!currentText && currentText !== placeholder && ( - + - + )} {!!extra && ( diff --git a/packages/react-native/src/search-bar/index.tsx b/packages/react-native/src/search-bar/index.tsx index 5dada4c5d9..54b489e1ff 100644 --- a/packages/react-native/src/search-bar/index.tsx +++ b/packages/react-native/src/search-bar/index.tsx @@ -1,6 +1,5 @@ import React, { FC, PropsWithChildren, useMemo } from 'react'; import { KeyboardTypeOptions, ReturnKeyTypeOptions, StyleProp, StyleSheet, TextStyle, ViewStyle } from 'react-native'; -import Animated, { FadeInRight, FadeOutRight } from 'react-native-reanimated'; import { useTheme } from '@shopify/restyle'; @@ -48,8 +47,6 @@ export type SearchBarProps = PropsWithChildren<{ activeOpacity?: number; }>; -const AnimatedTouchable = Animated.createAnimatedComponent(Pressable); - const SearchBar: FC = props => { const { placeholder = '搜索', @@ -92,17 +89,11 @@ const SearchBar: FC = props => { const CancelBtn = useMemo(() => { if (!showCancelButton || !focused) return null; return ( - + {cancelText} - + ); }, [showCancelButton, focused, activeOpacity, theme.spacing.x2, cancelText, onCancel]); diff --git a/packages/react-native/src/swipe-row/index.tsx b/packages/react-native/src/swipe-row/index.tsx index 96cc09eb70..e9ea344513 100644 --- a/packages/react-native/src/swipe-row/index.tsx +++ b/packages/react-native/src/swipe-row/index.tsx @@ -2,7 +2,7 @@ import React, { FC, PropsWithChildren } from 'react'; import { Animated as RNAnimated, StyleProp, StyleSheet, TextStyle, ViewStyle } from 'react-native'; import { RectButton } from 'react-native-gesture-handler'; import Swipeable from 'react-native-gesture-handler/Swipeable'; -import Animated, { FadeOutRight, LightSpeedInLeft } from 'react-native-reanimated'; +import Animated from 'react-native-reanimated'; import { useTheme } from '@shopify/restyle'; @@ -54,7 +54,7 @@ const SwipeRow: FC = ({ contentContainerStyle, }) => { const theme = useTheme(); - const { swipeableRef, changeState, handleRemove, visible } = useSwipeRow({ anchor, onRemove }); + const { swipeableRef, animatedStyle, changeState, handleLayout, handleRemove } = useSwipeRow({ anchor, onRemove }); const renderRightAction = ( props: SwipeAction & { x: number; progress: RNAnimated.AnimatedInterpolation } @@ -123,11 +123,9 @@ const SwipeRow: FC = ({ onSwipeableWillOpen={() => changeState(anchor)} containerStyle={containerStyle} > - {visible && ( - - {children} - - )} + + {children} + ); }; diff --git a/packages/react-native/src/swipe-row/useSwipeRow.ts b/packages/react-native/src/swipe-row/useSwipeRow.ts index 5d67af2754..a09d4bec23 100644 --- a/packages/react-native/src/swipe-row/useSwipeRow.ts +++ b/packages/react-native/src/swipe-row/useSwipeRow.ts @@ -1,5 +1,7 @@ import { useContext, useEffect, useRef } from 'react'; +import { LayoutChangeEvent } from 'react-native'; import { Swipeable } from 'react-native-gesture-handler'; +import { interpolate, useAnimatedStyle, useSharedValue, withTiming } from 'react-native-reanimated'; import { useMemoizedFn, useSafeState } from '@td-design/rn-hooks'; @@ -8,10 +10,10 @@ import { SwipeRowContext } from './context'; export default function useSwipeRow({ anchor, onRemove }: Pick) { const swipeableRef = useRef(null); + const isRemoving = useSharedValue(0); + const [height, setHeight] = useSafeState(0); const { changeState, id, multiple } = useContext(SwipeRowContext); - const [visible, setVisible] = useSafeState(true); - useEffect(() => { if (anchor === id && !multiple) { swipeableRef.current?.close(); @@ -20,15 +22,30 @@ export default function useSwipeRow({ anchor, onRemove }: Pick { await onRemove?.(); + isRemoving.value = withTiming(1, { duration: 200 }); swipeableRef.current?.close(); - setVisible(false); }; + const handleLayout = (e: LayoutChangeEvent) => { + setHeight(e.nativeEvent.layout.height); + }; + + const animatedStyle = useAnimatedStyle(() => { + if (isRemoving.value) { + return { + height: interpolate(isRemoving.value, [0, 1], [height, 0]), + }; + } + + return {}; + }); + return { swipeableRef, - visible, + animatedStyle, changeState, + handleLayout: useMemoizedFn(handleLayout), handleRemove: useMemoizedFn(handleRemove), }; } diff --git a/packages/react-native/src/vehicle-keyboard/VehicleKeyboardInput.tsx b/packages/react-native/src/vehicle-keyboard/VehicleKeyboardInput.tsx index 8958732fe8..6421bf68b9 100644 --- a/packages/react-native/src/vehicle-keyboard/VehicleKeyboardInput.tsx +++ b/packages/react-native/src/vehicle-keyboard/VehicleKeyboardInput.tsx @@ -1,6 +1,5 @@ import React, { forwardRef } from 'react'; import { Keyboard } from 'react-native'; -import Animated, { FadeInRight, FadeOutRight } from 'react-native-reanimated'; import { useTheme } from '@shopify/restyle'; @@ -16,7 +15,6 @@ import useVehicleKeyboard from './useVehicleKeyboard'; import VehicleKeyboardModal from './VehicleKeyboardModal'; const { ONE_PIXEL } = helpers; -const AnimatedTouchableIcon = Animated.createAnimatedComponent(Pressable); const VehicleKeyboardInput = forwardRef( ( { @@ -79,15 +77,9 @@ const VehicleKeyboardInput = forwardRef {allowClear && !disabled && !!currentText && currentText !== placeholder && ( - + - + )} {!!extra && ( diff --git a/packages/react-native/src/vehicle-keyboard/VehicleKeyboardItem.tsx b/packages/react-native/src/vehicle-keyboard/VehicleKeyboardItem.tsx index 9829a91571..a9f0197e78 100644 --- a/packages/react-native/src/vehicle-keyboard/VehicleKeyboardItem.tsx +++ b/packages/react-native/src/vehicle-keyboard/VehicleKeyboardItem.tsx @@ -1,6 +1,5 @@ import React, { forwardRef } from 'react'; import { Keyboard } from 'react-native'; -import Animated, { FadeInRight, FadeOutRight } from 'react-native-reanimated'; import { useTheme } from '@shopify/restyle'; @@ -14,7 +13,6 @@ import { VehicleKeyboardItemProps, VehicleKeyboardRef } from './type'; import useVehicleKeyboard from './useVehicleKeyboard'; import VehicleKeyboardModal from './VehicleKeyboardModal'; -const AnimatedTouchableIcon = Animated.createAnimatedComponent(Pressable); const VehicleKeyboardItem = forwardRef( ( { @@ -69,15 +67,9 @@ const VehicleKeyboardItem = forwardRef {allowClear && !disabled && !!currentText && currentText !== placeholder && ( - + - + )} {!!extra && ( diff --git a/packages/svgicon-cli/package.json b/packages/svgicon-cli/package.json index f9a5b40ca8..fd1db6c714 100644 --- a/packages/svgicon-cli/package.json +++ b/packages/svgicon-cli/package.json @@ -27,6 +27,10 @@ "lodash": "^4.17.21", "mkdirp": "^3.0.1" }, + "publishConfig": { + "access": "public", + "registry": "https://registry.npmjs.org/" + }, "devDependencies": { "@types/glob": "^8.1.0", "@types/lodash": "^4.14.195", @@ -38,4 +42,4 @@ "gulp-typescript": "^6.0.0-alpha.1", "typescript": "^5.1.6" } -} +} \ No newline at end of file