2017-05-30 9 views
0

カルーセルの要素のボタンの画像を変更しようとしています。私は現在のカルーセルのイメージだけを変更したいと思います。何か案は?おかげネイティブのonPressアクティブな状態に反応します。カルーセルの画像ソースを変更します。

class CarouselImages extends React.Component { 
    constructor(props) { 
     super(props); 
     this.state = { 
      myImagesArray: [ 
       { 
        key: 1, 
        title: 'Category' 
       }, 
       { 
        key: 2, 
        title: 'Category' 
       }, 
       { 
        key: 3, 
        title: 'Category' 
       } 
      ], 
      icon_active: false, 
     } 

     activateCarouselButton = a => { 
      const newState = Object.assign(
       {}, 
       { 
        icon_active: false, 
       }, 
       { [a]: true }, 
      ) 
      this.setState(newState); 
     } 
    } 

    render =() => { 
     const { icon_active } = this.state; 
     var myCarousel = this.state.myImagesArray.map(function (index) { 
      return (
       <View key={index}> 
        <TouchableHighlight onPress={() => activateCarouselButton('icon_active')} > 
         <Image 
          source={icon_active ? require('../Image/[email protected]') : require('../Image/[email protected]')} /> 
        </TouchableHighlight> 
       </View> 
      ); 
     }); 

     return (
      <View> 
       <Carousel 
        style={{ backgroundColor: '#fff' }}> 
        {myCarousel} 
       </Carousel> 
      </View> 
     ) 
    } 
} 

答えて

0

あなたがicon_active状態ではなく、ブールのアイコンのkeyを保持する必要があります。これは、あなたにそれを行う方法の勘弁を与える:

関連する問題