14

RN ScrollView滑动不到底部问题

 3 years ago
source link: https://renyugang.blog.csdn.net/article/details/89914582
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

RN ScrollView滑动不到底部问题

在这里插入图片描述

先怀疑是RN版本问题:(根据创建不一样的rn项目demo来进行测试,和项目一致的版本来测试,最终问题锁定在我们自己修改的代码上。)

react-native init projectname 创建RN项目,里面会有android/ios的工程

react-native init projectname --verbose --version 0.41.0 指定RN版本创建

react-native run-android 直接把RN Android项目运行到手机,并且会连接到RN代码

RN入口代码修改 - 新RN版本: App.js / 旧版本: index.android.js

最近工作中遇到一个前人留的坑,网上找了下,发现很多人都有遇到RN ScrollView滑动不到底部的问题,但是什么flex:1的方案,尝试过后发现问题依旧。

那么我们如何定位这个问题?
首先ScrollView的话,它的高度也是由我们控件的高度决定的。
那么我们的View是由我们addView进去的ViewGroup.LayoutParams决定。

那么找到我们的代码:
Height的计算:ScreenHeight(屏幕高度,记得考虑刘海屏的情况) - (虚拟导航栏高度[如果存在]) - (我们的titleBar高度) - (状态栏高度)
我们的Height计算有误,进行修改后,依旧有问题。
仔细看了下,在addView上也有问题,改为:

mViewGroup.addView(mReactView, ViewGroup.LayoutParams.MATCH_PARENT, vHeight); //vHeight为我们计算出来的区域高度


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK