Skip to content

Instantly share code, notes, and snippets.

@Karthik-B-06
Last active May 23, 2020 13:04
Show Gist options
  • Save Karthik-B-06/6725f1cd7ef9750719476ea6a7390ec8 to your computer and use it in GitHub Desktop.
Save Karthik-B-06/6725f1cd7ef9750719476ea6a7390ec8 to your computer and use it in GitHub Desktop.
React Native Search Box - App.js
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