diff --git a/native/chat/chat-thread-list.react.js b/native/chat/chat-thread-list.react.js --- a/native/chat/chat-thread-list.react.js +++ b/native/chat/chat-thread-list.react.js @@ -83,7 +83,7 @@ ]; /* eslint-disable import/no-named-as-default-member */ -const { Value, Node, interpolateNode } = Animated; +const { Value, Node, interpolateNode, useValue } = Animated; /* eslint-enable import/no-named-as-default-member */ type Item = @@ -126,6 +126,9 @@ +setOpenedSwipeableID: SetState, +numItemsToDisplay: number, +setNumItemsToDisplay: SetState, + +searchCancelButtonOpen: Value, + +searchCancelButtonProgress: Node, + +searchCancelButtonOffset: Node, }; class ChatThreadList extends React.PureComponent { @@ -133,20 +136,9 @@ flatList: ?FlatList; scrollPos = 0; clearNavigationBlurListener: ?() => mixed; - searchCancelButtonOpen: Value = new Value(0); - searchCancelButtonProgress: Node; - searchCancelButtonOffset: Node; constructor(props: Props) { super(props); - this.searchCancelButtonProgress = animateTowards( - this.searchCancelButtonOpen, - 100, - ); - this.searchCancelButtonOffset = interpolateNode( - this.searchCancelButtonProgress, - { inputRange: [0, 1], outputRange: [0, 56] }, - ); } componentDidMount() { @@ -207,9 +199,9 @@ const wasActiveOrActivating = prevSearchStatus === 'active' || prevSearchStatus === 'activating'; if (isActiveOrActivating && !wasActiveOrActivating) { - this.searchCancelButtonOpen.setValue(1); + this.props.searchCancelButtonOpen.setValue(1); } else if (!isActiveOrActivating && wasActiveOrActivating) { - this.searchCancelButtonOpen.setValue(0); + this.props.searchCancelButtonOpen.setValue(0); } const { flatList } = this; @@ -269,7 +261,7 @@ renderSearch(additionalProps?: $Shape>) { const animatedSearchBoxStyle: AnimatedStyleObj = { - marginRight: this.searchCancelButtonOffset, + marginRight: this.props.searchCancelButtonOffset, }; const searchBoxStyle = [ this.props.styles.searchBox, @@ -277,7 +269,7 @@ ]; const buttonStyle = [ this.props.styles.cancelSearchButtonText, - { opacity: this.searchCancelButtonProgress }, + { opacity: this.props.searchCancelButtonProgress }, ]; return ( @@ -636,6 +628,20 @@ const [openedSwipeableID, setOpenedSwipeableID] = React.useState(''); const [numItemsToDisplay, setNumItemsToDisplay] = React.useState(25); + const searchCancelButtonOpen: Value = useValue(0); + const searchCancelButtonProgress: Node = React.useMemo( + () => animateTowards(searchCancelButtonOpen, 100), + [searchCancelButtonOpen], + ); + const searchCancelButtonOffset: Node = React.useMemo( + () => + interpolateNode(searchCancelButtonProgress, { + inputRange: [0, 1], + outputRange: [0, 56], + }), + [searchCancelButtonProgress], + ); + return ( ); }