2017-01-25 9 views
4

을 마친 후 반작용 네이티브 ActivityIndicator 내가 레이아웃에 로드 가져 오는 동안 보여줍니다 componentDidMount이 발사 될 때 바퀴가 사라지지만 계속 ActivityIndicator 및 빈 블록 공간이 숨기지 않습니다. 이 구성 요소를 분리하는 방법을 추측하고 있지만 나에게 도움이되는 모든 것이 있습니다.애니메이션

것은 내가 현재이 버전 함께 일하고 있어요 :

import React, { Component } from 'react'; 
import { 
    StyleSheet, 
    View, 
    ... // Couple more components here 
    ActivityIndicator, 
} from 'react-native'; 

import NewsList from './NewsList'; 

export default class HomeView extends Component { 

    constructor(props) { 
    super(props); 
    this.state = { 
     noticias: [], 
     animating: true, 
    }; 
    } 

componentDidMount(){ 
    fetchFunction() // My fetch function here 
     .then(data => this.setState({ data:data })) 
     this.state.animating = false 
    } 

render() { 

    return (
     <View> 
      <NewsList data={data} /> // My custom component 

      <ActivityIndicator 
      animating={this.state.animating} 
      style={[{height: 80}]} 
      color="#C00" 
      size="large" 
      hidesWhenStopped={true} 
      /> 
     </View> 
    ); 

    } 
} 

PS :

react-native-cli: 2.0.1 
react-native: 0.40.0 

이 내가 사용하고 코드의 일부입니다 내가 돌아 오는을 사용하지 않는. 당신이 당신의 구성 요소를 다시 렌더링하려면

ActivityIndicator with animation working fine The empty space when animating is set to false

+0

'this.state.animating = false' 왜 세트를 사용하지 않았습니까? 이전 줄의 상태? – RRikesh

+0

나는 '.then (data => this.setState ({data : data, animating : false}))' 과 같은 결과를 얻었습니다. – vtisnado

답변

11

나는 우리가 아무것도

를로드하지 않을 때 조건부 https://facebook.github.io/react/docs/jsx-in-depth.html

내가 완전히 DOM에서 ActivityIndicator을 제거 할 내용을 표시하는 방법에 대한 JSX에 대한 자세한 내용을하는 것이 좋습니다

import React, { Component } from 'react'; 
import { View, ActivityIndicator } from 'react-native'; 

import NewsList from './NewsList'; 

export default class HomeView extends Component { 
    state = { 
    data: [], 
    isLoading: true, 
    } 

    componentDidMount() { 
    fetchFunction() 
     .then(data => this.setState({ data, isLoading: false })) 
    } 

    render() { 
    const {data, isLoading} = this.state; 

    return (
     <View> 
     <NewsList data={data} /> 
     {isLoading && (
      <ActivityIndicator 
      style={{ height: 80 }} 
      color="#C00" 
      size="large" 
      /> 
     )} 
     </View> 
    ); 
    } 
} 
+0

감사합니다.이게 많이 도움이됩니다 .DXX 문서를 확인하겠습니다. 이제 예상대로 작동합니다. – vtisnado

+0

모두 다른 사람들이 쉽게 찾을 수 있도록이 대답을 올바른 것으로 표시합니다. :) –

3

당신은 setState를를 사용한다.

this.setState({ animating: false }) 

대신

this.state.animating = false 
+0

나는 React (1 주일) 또는 그래서), 그 라인에 오류를 발견하지 않았다. 언급 할 시간을내어 주셔서 감사합니다. 그러나 이제는 문제가 해결되었지만 "공백"공간이 지속됩니다. ( – vtisnado