React Native 獲取組件(Component)在屏幕上的位置


年后主客戶端的需求以及老的業務遷移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。 一起探討一起進步。。。。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM