动态添加的视图没有样式函数React Native

时间:2017-06-30 16:03:09

标签: javascript android reactjs react-native view

我在我的应用中使用轮播(取自https://github.com/nick/react-native-carousel}

每次用户向右滑动时,我都会尝试添加视图。

这就是我正在使用的代码:

myArray.length==0

我成功添加了一个视图,但它不是样式,文本'页码:'和索引......

enter image description here

enter image description here

Why doesn't it have the style and content as the previous ones?

更新

更改了我的代码,但仍然无效...

export default class AllRand extends Component
{ 

  constructor(props)
  {    
    super(props);
    this.state = 
    {
      myArr: ['Page numebr: ', 'Page numebr: ']
    };
  } 

  _onPageSwitchAnimateEnd()
  {
    this.state.myArr.push('Page numebr: ')
    this.setState({
        myArr: this.state.myArr
    })
  }

  render()
  {    
    let Arr = this.state.myArr.map((text, index) => {
      return <View key={ index } style={ styles.shit1 }><Text>asdasd { index }</Text></View>                            
    })      

    return (
      <Carousel animate={false} hideIndicators={false} onPageChange={() => this._onPressOut()}>
        { Arr }
      </Carousel>
    );
  }
}

1 个答案:

答案 0 :(得分:1)

所以最终问题是因为我使用的Carousel库中存在一个错误(https://github.com/nick/react-native-carousel)。由于某种原因,添加页面的回调函数会弄乱页面数组(不知道为什么......)。]

当我尝试使用另一个Carousel库时,该功能起作用。

我可以根据这一经验给出的唯一建议是,当您认为为了修复您的错误而尝试了所有可能性时,请尝试更改您正在使用的库(到另一个相同的功能库)。