2017-04-10 10 views
0

アプリケーションの特定のセクションに到達したときにStatusBarのbackgroundColorプロパティを変更するにはどうすればよいですか?React Native - 特定のセクションに到達したときにステータスバーの色を変更します。

例:私はView(Section)を持っています。デフォルトのbackgroundColorは赤です。そのセクションまでスクロールすると、StatusBar backgroundColorを青に変更します。 (:私はネイティブベースを使用してい注):

は、ここで私はそれをしたいコンポーネントの

  <Container> 
      <StatusBar backgroundColor='#2c3e50' barStyle='dark-content' /> 
      <Content> 
       <Grid> 
        <Col> 
         <Row> 
          <Text> 
           App title name 
          </Text> 
         </Row> 
        </Col> 
        <Row> 
         <Col> 
          <Text> 
           Random description 
          </Text> 
         </Col> 
        </Row> 
        <Col> 
         <Row> 
          <Text> 

          </Text> 
         </Row> 
        </Col> 
        <Row> 
         <Col style={{padding: 20, backgroundColor: '#2980b9'}}> 
          <Text style={{color: 'white', textAlign: 'justify'}}> 
           Random text 
          </Text> 
          <Text style={{ color: 'white', paddingTop: 10, textAlign: 'justify'}}> 
           More random text 
          </Text> 
         </Col> 
        </Row> 
        <Row> 
         <Col style={{backgroundColor: '#1abc9c'}}> 
          <Text style={{color: 'white', fontSize: 40, textAlign: 'center'}}> 
           Chocolate 
          </Text> 
         </Col> 
        </Row> 
        <Row> 
         <Col> 
          <Text> 
           Random txt 
          </Text> 
         </Col> 
        </Row> 
       </Grid> 
      </Content> 
     </Container> 
+0

あなたは代わりに何をしましたか –

答えて

0

まずScrollViewreac-nativeコンポーネントとContentを交換してください。状態に背景色を追加し、ScrollViewが特定の位置で反応したときに背景色を更新します。 onScroll機能を使用して、ScrollViewの位置を検出します。

注:Contentネイティブ・ベース成分がScrollViewreac-nativeコンポーネントと類似している場合、その後、あなたはそれを交換する必要はありません。私は経験がありませんnative-base

+0

私はそれを行うことができましたが、私は 'contentOffset.y'を使用しているので、他のどのデバイスでも動作させる方法はありません。私の電話の価値。私はすべてのデバイスのY軸の 'セクション'の位置を計算し、それを使って何かを作る方法を知りたいと思います。 –

+0

セクションのy位置を見つけるには[onLayout](https://facebook.github.io/react-native/docs/view.html#onlayout)を使います。 –

関連する問題