Last active
May 23, 2020 13:04
-
-
Save Karthik-B-06/6725f1cd7ef9750719476ea6a7390ec8 to your computer and use it in GitHub Desktop.
React Native Search Box - App.js
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, { useState } from 'react'; | |
| import { Animated, SafeAreaView, StatusBar } from 'react-native'; | |
| import LoaderComponent from './src/LoaderComponent'; | |
| import SearchComponent from './src/SearchComponent'; | |
| console.disableYellowBox = true; | |
| const App = () => { | |
| const [scrollYValue, setScrollYValue] = useState(new Animated.Value(0)); | |
| const clampedScroll = Animated.diffClamp( | |
| Animated.add( | |
| scrollYValue.interpolate({ | |
| inputRange: [0, 1], | |
| outputRange: [0, 1], | |
| extrapolateLeft: 'clamp', | |
| }), | |
| new Animated.Value(0), | |
| ), | |
| 0, | |
| 50, | |
| ) | |
| const array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; | |
| return ( | |
| <Animated.View> | |
| <StatusBar barStyle="dark-content" /> | |
| <SafeAreaView> | |
| <SearchComponent clampedScroll={clampedScroll} /> | |
| <Animated.ScrollView | |
| showsVerticalScrollIndicator={false} | |
| style={{ | |
| margin: 20, | |
| backgroundColor: 'white', | |
| paddingTop: 55 | |
| }} | |
| contentContainerStyle={{ | |
| display: 'flex', | |
| flexDirection: 'row', | |
| flexWrap: 'wrap', | |
| justifyContent: 'space-around' | |
| }} | |
| onScroll={Animated.event( | |
| [{ nativeEvent: { contentOffset: { y: scrollYValue } } }], | |
| // { useNativeDriver: true }, | |
| () => { }, // Optional async listener | |
| )} | |
| contentInsetAdjustmentBehavior="automatic"> | |
| {array.map(item => <LoaderComponent />)} | |
| </Animated.ScrollView> | |
| </SafeAreaView> | |
| </Animated.View> | |
| ); | |
| }; | |
| export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment