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ルートに行く場合:

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); 
    } 
    ... 
} 

を、私はエラーを取得する:Uncaught TypeError: Converting circular structure to JSON

は、私はちょうどそのrefの高さを取得したいです。私は何が欠けていますか?

+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

関連する問題