Last active
June 12, 2020 16:47
-
-
Save Karthik-B-06/c169f35df2e17c4ffc829731e6d0e96b to your computer and use it in GitHub Desktop.
React Native Search
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from 'react'; | |
| import { Animated, StyleSheet, TextInput } from 'react-native'; | |
| import { deviceWidth } from './LoaderComponent'; | |
| const SearchComponent = (props) => { | |
| const { | |
| clampedScroll | |
| } = props; | |
| const searchBarTranslate = clampedScroll.interpolate({ | |
| inputRange: [0, 50], | |
| outputRange: [0, -(250)], | |
| extrapolate: 'clamp', | |
| }); | |
| const searchBarOpacity = clampedScroll.interpolate({ | |
| inputRange: [0, 10], | |
| outputRange: [1, 0], | |
| extrapolate: 'clamp', | |
| }); | |
| return ( | |
| <Animated.View style={[ | |
| styles.container, | |
| { | |
| transform: [ | |
| { | |
| translateY: searchBarTranslate | |
| } | |
| ], | |
| opacity: searchBarOpacity, | |
| } | |
| ]}> | |
| <TextInput | |
| placeholder='Search' | |
| style={styles.formField} | |
| placeholderTextColor={'#888888'} | |
| /> | |
| </Animated.View> | |
| ) | |
| } | |
| const styles = StyleSheet.create({ | |
| container: { | |
| position: 'absolute', | |
| top: 50, | |
| width: deviceWidth - 40, | |
| left: 20, | |
| zIndex: 99, | |
| backgroundColor: 'white' | |
| }, | |
| formField: { | |
| borderWidth: 1, | |
| padding: 12, | |
| paddingLeft: 20, | |
| paddingRight: 20, | |
| borderRadius: 20, | |
| borderColor: '#888888', | |
| fontSize: 18, | |
| height: 50 | |
| } | |
| }) | |
| export default SearchComponent; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment