Last Updated on : 2025-07-29 03:04:59download
Carousel is a slideshow component.
Note:
For more information, see Carousel Demo.
The slideshow component must set the height of the component. You can add onLayout={e => this.\_onLayout(e)} to the parent component, and obtain the parent element height. Alternatively, you can set the height of the slideshow component with a variable, and make adaptive settings.
import React from "react";
 import { View, StyleSheet, TouchableOpacity } from "react-native";
 import { Carousel, TYText } from "tuya-panel-kit";
 
class CarouselScene extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      index: 0,
    };
  }
  render() {
    return (
      <View style={styles.containerStyle}>
        <Carousel
          style={{ height: 180 }}
          selectedIndex={this.state.index}
          autoplay={true}
          loop={true}
          carouselChange={(index) => console.log(index)}
        >
          <View style={{ flex: 1, backgroundColor: "red" }}>
            <TYText style={{ color: "#333" }}>Carousel 1</TYText>
          </View>
          <View style={{ flex: 1, backgroundColor: "blue" }}>
            <TYText style={{ color: "#333" }}>Carousel 2</TYText>
          </View>
          <View style={{ flex: 1, backgroundColor: "yellow" }}>
            <TYText style={{ color: "#333" }}>Carousel 3</TYText>
          </View>
        </Carousel>
        <TouchableOpacity onPress={() => this.setState({ index: 1 })}>
          <TYText>Click Me! </TYText>
        </TouchableOpacity>
      </View>
    );
  }
 }
 
export default CarouselScene;
 
const styles = StyleSheet.create({
  containerStyle: {
    flex: 1,
    paddingHorizontal: 16,
  },
 });
Style of the carousel.
| Type | Required | Default value | 
|---|---|---|
| ViewPropTypes.style | No | None | 
Style of the indication dot.
| Type | Required | Default value | 
|---|---|---|
| ViewPropTypes.style | No | None | 
Style of the currently activated indication dot.
| Type | Required | Default value | 
|---|---|---|
| ViewPropTypes.style | No | None | 
Style of the indication dot wrapper.
| Type | Required | Default value | 
|---|---|---|
| ViewPropTypes.style | No | None | 
Whether scroll bouncing occurs when the content range is larger than the scroll view itself.
| Type | Required | Default value | 
|---|---|---|
| boolean | No | true | 
Whether there are indication dots.
| Type | Required | Default value | 
|---|---|---|
| boolean | No | true | 
Whether to loop.
| Type | Required | Default value | 
|---|---|---|
| boolean | No | false | 
Whether Android implementation mechanism uses viewPager.
| Type | Required | Default value | 
|---|---|---|
| boolean | No | true | 
Whether to play automatically.
| Type | Required | Default value | 
|---|---|---|
| boolean | No | false | 
Automatic play interval in milliseconds.
| Type | Required | Default value | 
|---|---|---|
| number | No | 2000 | 
The currently activated index.
| Type | Required | Default value | 
|---|---|---|
| number | No | 0 | 
Custom indication dots.
| Type | Required | Default value | 
|---|---|---|
| props => React.ReactNode | No | defaultDots | 
Switch callback.
| Type | Required | Default value | 
|---|---|---|
| index => void | No | None | 
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback