年后主客戶端的需求以及老的業務遷移RN,現在瘋狂的在學RN。在遷移需求的時候遇到需要獲取組件在屏幕上的絕對位置。頁面如下:
就需要展開的時候獲取sectionHeader(默認排序)在屏幕上的具體位置,核心代碼如下:
renderSectionHeaderContent() {
return ( <SectionHeader ref={(sectionHeader) => { this.sectionHeader = sectionHeader; }} title={this.state.sectionHeaderTitle} clickSectionHeader={() => { const handle = findNodeHandle(this.sectionHeader); UIManager.measure(handle, (x, y, width, height, pageX, pageY) => { }); }} /> ); }
注:需要 import { UIManager} from 'NativeModules'; x、y:為視圖的相對位置。width、height:為視圖的寬度和高度。pageX、pageY為視圖在屏幕上的絕對位置。
================================================================
初學React Native 。若有疑問請加本人QQ:610774281 微信:stephenli225。 一起探討一起進步。。。。