Skip to content

Instantly share code, notes, and snippets.

@PrasathRavichandran
Created June 8, 2022 03:20
Show Gist options
  • Save PrasathRavichandran/5f6f984c49b52f00c323797a9e337c44 to your computer and use it in GitHub Desktop.
Save PrasathRavichandran/5f6f984c49b52f00c323797a9e337c44 to your computer and use it in GitHub Desktop.
import React, {useRef} from 'react';
...
const inputRef = useRef<any>(null);
...
const onFocus = ()=>{
InputLength.value = {width: '90%'};
SearchTextPlacement.value = {transformX: 0};
CancelBtn.value = {transformX: 0};
}
const onCancelAnimation = () => {
InputLength.value = {width: '100%'};
SearchTextPlacement.value = {
transformX: (Dimensions.get('window').width - 140) / 2,
};
CancelBtn.value = {transformX: 100};
inputRef.current.blur();
};
...
<TextInput
placeholder={'Search'}
style={{fontSize: 16, paddingRight: 20}}
onFocus={onFocus}
ref={inputRef}
/>
...
<Animated.View style={[styles.cancelBtnContainer, CancelBtnStyles]}>
<TouchableOpacity onPress={onCancelAnimation}>
<Text>Cancel</Text>
</TouchableOpacity>
</Animated.View>
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment