react native引用原生组件时无法显示的问题处理

最近有个需求,要在react native中嵌入一个原生的视频组件,同事嵌入后发现有问题:

  1. 内容无法显示

https://musicfe.com/rn-android-webview

参考这个方法,在嵌入之后调用一下。

java 复制代码
public void manuallyLayoutChildren(View view) {
    int width = view.getMeasuredWidth();
    int height = view.getMeasuredHeight();
    view.measure(
            View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY),
            View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY));
    view.layout(0, 0, width, height);
}
  1. 内容动态变化时的高宽不对,以及原生的edittext输入框无法删除

看了一下,是因为内容变化的时候,一是requestLayout没有正常执行;二是上面云音乐给的代码中,没有触发子view的重绘,所以子view的布局失效了。处理方法

java 复制代码
@Override
public void requestLayout() {
    super.requestLayout();
    CustomView.this.post(() -> {
        if (ViewCompat.isAttachedToWindow(CustomView.this)) {
            layoutViews(CustomView.this);
        }
    });
}

public void layoutViews(View view) {
    int width = view.getMeasuredWidth();
    int height = view.getMeasuredHeight();
    view.measure(View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY),View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY));
    view.layout(0, 0, width, height);
    view.invalidate();
}

玩~

相关推荐
前端小D2 天前
React Native项目开发(iOS侧为例)
javascript·react native·react.js
大龄秃头程序员3 天前
从源码里看懂 React Native 新架构:TurboModule 与 Fabric 到底是怎么跑起来的?
react native
前端小D4 天前
React Native Android 项目搭建
android·react native·react.js
hhhjhl6 天前
React Native 三方库「react-native-sha256」的鸿蒙化适配指南
react native·华为·harmonyos
2601_949970696 天前
React Native 三方库「react-native-version-check」的鸿蒙化适配指南
react native·华为·harmonyos
hhhjhl6 天前
React Native 三方库「react-native-proximity」的鸿蒙化适配指南
react native·华为·harmonyos
2601_949970696 天前
React Native 三方库「react-native-media-notification」的鸿蒙化适配指南
react native·华为·harmonyos
GitCode官方6 天前
从大语言模型到具身智能:百度百舸 LoongForge 入驻 AtomGit
人工智能·react native·百度·harmonyos·atomgit
2501_915918419 天前
Windows 上开发 React Native iOS,真机调试、Fast Refresh 与打包 ipa
windows·vscode·react native·ios·个人开发·swift·敏捷流程
2501_9481226310 天前
Qs 跨端三方库仓颉适配全流程
python·react native·django·tornado