1

ref 만있는 경우 반응 네이티브 요소의 높이를 측정 할 수 있습니까?반응 네이티브 ref (ListView)의 높이 측정

NativeMethodsMixin을 참조하십시오. 그러나 구현 방법이 명확하지 않습니다.

나는 그것을 포함 시도했다 :

import { NativeMethodsMixin } from 'react-native'; 
class Foo extends Component { 
    mixins: [NativeMethodsMixin] 
    measure(ref) { 
    console.log(NativeMethodsMixin.measure(ref)); 
    } 
    ... 
} 

하지만 응용 프로그램은 NativeMethodsMixin이 정의되지 불평.

나는 RCTUIManager 경로를 이동하는 경우 : Uncaught TypeError: Converting circular structure to JSON

난 그냥 그 ref의 높이를 얻으려면 :

import { NativeModules } from 'react-native'; 
const RCTUIManager = NativeModules.UIManager; 
class Foo extends Component { 
    measure(ref) { 
    const height = RCTUIManager.measure(ref, (x, y, width, height, pageX, pageY) => height)); 
    console.log(height); 
    } 
    ... 
} 

다음 나는 오류가 발생합니다. 내가 뭘 놓치고 있니?

+0

이 발견하는. https://facebook.github.io/react/docs/more-about-refs.html – chandlervdw

답변

0

당신은 다음과 같이 수행 할 수 있습니다

this.refs[your ref key].measure((fx, fy, width, height, px, py) => { 
      this.state.origins.push({ 
      x: px, 
      y: py, 
      width, 
      height, 
      }); 
     }); 

어쩌면 도움이 링크 : - 당신은`ref`을 사용할 수 있고, 실제는 클래스 인스턴스를 백업 반응하지 사람들을위한 click here