import { H3 } from '@expo/html-elements';
import * as React from 'react';
import {
Platform,
ScrollView,
StyleSheet,
Image,
Text,
TouchableOpacity,
useWindowDimensions,
View,
RefreshControl,
} from 'react-native';
import Button from '../components/Button';
import TitleSwitch from '../components/TitledSwitch';
export default function ScrollViewScreen() {
const [isHorizontal, setHorizontal] = React.useState(true);
const [isEnabled, setEnabled] = React.useState(true);
const [isRefreshing, setRefreshing] = React.useState(false);
const [removeClippedSubviews, setRemoveClippedSubviews] = React.useState(false);
const scrollView = React.useRef(null);
const axis = isHorizontal ? 'x' : 'y';
const { width } = useWindowDimensions();
const isMobile = width <= 640;
const imageStyle = {
width,
height: width / 2,
};
React.useEffect(() => {
let timeout: any;
if (isRefreshing) {
timeout = setTimeout(() => setRefreshing(false), 2000);
}
return () => {
clearTimeout(timeout);
};
}, [isRefreshing]);
const onRefresh = () => {
setRefreshing(true);
};
const items = React.useMemo(() => [...Array(20)].map((_, i) => `Item ${i}`), []);
return (
}>
{
console.log('onScroll!');
}}
scrollEventThrottle={200}
scrollEnabled={isEnabled}
nestedScrollEnabled
horizontal={isHorizontal}
ref={scrollView}
style={styles.scrollView}>
{items.map((title: string, index: number) => (
- {title}
))}
Scroll to
{
if (scrollView.current) {
scrollView.current.flashScrollIndicators();
}
}}
/>
Pagination
);
}
ScrollViewScreen.navigationOptions = {
title: 'ScrollView',
};
function Item(props: { children: React.ReactNode }) {
return (
{props.children}
);
}
const styles = StyleSheet.create({
scrollView: {
backgroundColor: '#eeeeee',
height: 300,
flex: 1,
maxHeight: 300,
},
text: {
fontSize: 16,
fontWeight: 'bold',
paddingVertical: 8,
},
item: {
margin: 5,
padding: 8,
backgroundColor: '#cccccc',
borderRadius: 3,
minWidth: 96,
maxHeight: 96,
},
});