Измерьте высоту реакционно-родной ссылки (ListView)
Как вы можете измерить высоту реактивно-родного элемента, если у вас есть только ref
?
Я вижу 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
, Что мне не хватает?
1 ответ
Вы можете сделать так:
this.refs[your ref key].measure((fx, fy, width, height, px, py) => {
this.state.origins.push({
x: px,
y: py,
width,
height,
});
});
эта ссылка может быть полезной: нажмите здесь