To implement auto-scrolling, wrap your target components (like Text or Image) inside the <AutoScroll> component. The component handles the animation logic automatically.
import * as React from 'react';
import { Text, View, Image, StyleSheet } from 'react-native';
import AutoScroll from '@homielab/react-native-auto-scroll';
export default class App extends React.Component {
render() {
return (
<View style={styles.container}>
{/* Example with an Image */}
<AutoScroll style={styles.scrolling1}>
<Image
style={styles.image}
source={require('./assets/merry-christmas-png.png')}
/>
</AutoScroll>
{/* Example with Text and custom padding */}
<AutoScroll style={styles.scrolling2} endPaddingWidth={50}>
<Text style={styles.welcome}>MERRY CHRISTMAS AND HAPPY NEW YEAR</Text>
</AutoScroll>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
image: {
width: 200,
height: 200,
},
scrolling1: {
width: 400,
padding: 10,
marginBottom: 10,
},
scrolling2: {
backgroundColor: 'red',
width: 400,
padding: 10,
marginBottom: 10,
},
welcome: {
color: 'white',
fontSize: 20,
fontWeight: 'bold',
textAlign: 'center',
margin: 10,
},
});