Swiper/App.tsx

52 lines
1.2 KiB
TypeScript
Raw Normal View History

2022-12-18 18:32:44 +13:00
import {useState} from 'react'
import {Button, View} from 'react-native'
import AppIntroSlider from 'react-native-app-intro-slider'
import DocumentPicker, {
DocumentPickerResponse,
2022-12-18 18:32:44 +13:00
} from 'react-native-document-picker'
import {backgroundColor} from './constants'
import Item from './Item'
export default function App() {
2022-12-18 18:32:44 +13:00
const [files, setFiles] = useState<DocumentPickerResponse[]>([])
const [slide, setSlide] = useState(0)
const pick = async () => {
2022-12-18 18:32:44 +13:00
const picked = await DocumentPicker.pickMultiple()
console.log(`Picked ${picked.length} files.`)
setFiles(picked)
}
const renderItem = ({
item,
index,
}: {
2022-12-18 18:32:44 +13:00
item: DocumentPickerResponse
index: number
}) => {
2022-12-18 18:32:44 +13:00
return <Item index={index} slide={slide} value={item} />
}
return (
2022-12-18 18:32:44 +13:00
<View
style={{
backgroundColor,
justifyContent: 'space-between',
flex: 1,
flexGrow: 1,
padding: 10,
}}>
<Item />
<AppIntroSlider
style={{backgroundColor}}
data={files}
renderItem={renderItem}
2022-12-18 18:32:44 +13:00
onSlideChange={setSlide}
showDoneButton={false}
2022-12-18 18:32:44 +13:00
initialNumToRender={3}
/>
2022-12-18 18:32:44 +13:00
<Button title="Pick" onPress={pick} />
</View>
2022-12-18 18:32:44 +13:00
)
}