DefinitelyTyped/types/react-native-snap-carousel/react-native-snap-carousel-tests.tsx
jnbt 97c89cee56 Update react-native-snap-carousel to 2.4 (#18347)
* Update react-native-snap-carousel to 2.3.1

* Changes bases on react-native-snap-carousel 2.3.0 / 2.3.1 (https://github.com/archriss/react-native-snap-carousel/releases/tag/v2.3.0)
  * Adds prop: `scrollEndDragDebounceValue`
  * Removes props: `scrollEndDragThrottleValue`, `snapCallbackDebounceValue`
  * Adds getter: `currentScrollPosition`
* Changes based on react-native new `StyleProp` type:
  * Uses `StyleProp` for `contentContainerCustomStyle` and `slideStyle`

* Update react-native-snap-carousel to 2.4.0

Changes bases on react-native-snap-carousel 2.4.0 (https://github.com/archriss/react-native-snap-carousel/releases/tag/v2.4.0):

* Add defintion of new `Pagination` component
2017-07-24 11:58:20 -07:00

111 lines
3.2 KiB
TypeScript

import * as React from 'react';
import {
LayoutChangeEvent,
NativeSyntheticEvent,
NativeScrollEvent,
StyleSheet,
Text,
View,
ViewStyle
} from 'react-native';
import Carousel, { Pagination } from 'react-native-snap-carousel';
class SnapCarouselTest extends React.Component<{}, {}> {
render(): React.ReactElement<any> {
return (
<View>
<Carousel
itemWidth={75}
sliderWidth={300}
/>
<Carousel
itemWidth={75}
sliderWidth={300}
containerCustomStyle={styles.container}
enableMomentum={true}
keyboardDismissMode='interactive'
onSnapToItem={this.onSnapToItem}
onScroll={this.onScroll}
onLayout={this.onLayout}
scrollEndDragDebounceValue={100}
vertical={false}
>
<View
style={styles.item}
>
<Text>Item #1</Text>
</View>
</Carousel>
<Carousel
itemHeight={75}
sliderHeight={300}
vertical={true}
/>
</View>
);
}
private onSnapToItem = (index: number) => {
console.log("Snapped to: ", index);
}
private onScroll = (event: NativeSyntheticEvent<NativeScrollEvent>) => {
console.log("Scrolled: ", event);
}
private onLayout = (event: LayoutChangeEvent) => {
console.log("Layout: ", event);
}
}
class SnapCarouselWithPaginationTest extends React.Component<{}, {activeSlide: number}> {
constructor(props: {}) {
super(props);
this.state = { activeSlide: 0 };
}
render(): React.ReactElement<any> {
return (
<View>
<Carousel
itemWidth={75}
sliderWidth={300}
keyboardDismissMode='interactive'
onSnapToItem={(index) => this.setState({ activeSlide: index })}
>
<View>
<Text>Item #1</Text>
</View>
<View>
<Text>Item #2</Text>
</View>
</Carousel>
<Pagination
dotsLength={2}
activeDotIndex={this.state.activeSlide}
containerStyle={{ backgroundColor: 'rgba(0, 0, 0, 0.75)' }}
dotStyle={{
width: 10,
height: 10,
borderRadius: 5,
marginHorizontal: 8,
backgroundColor: 'rgba(255, 255, 255, 0.92)'
}}
inactiveDotOpacity={0.4}
inactiveDotScale={0.6}
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1
} as ViewStyle,
item: {
width: 75
} as ViewStyle,
});