ios - React Native自定义组件不会动态设置组件的大小

标签 ios react-native twitter-fabric

我正在尝试构建一个显示推文的 RN 组件。我 fork 了一个很棒的 RN 组件,react-native-fabric-twitterkit,并添加了一个显示推文的组件。到目前为止一切顺利,但是当我想在 ScrollView 中显示该推文时,我必须指定组件的高度和宽度,否则它将不会显示。知道我做错了什么吗?

这是我 fork 的 RN 组件:https://github.com/adamivancza/react-native-fabric-twitterkit

这是一个展示我的问题的测试应用程序:https://github.com/adamivancza/react-native-twitterkit-test

<View style={styles.container}>
    <ScrollView
      style={{ flex: 1 }}>
      // this component is displayed because I've set a specific height 
      <Tweet
        style={{ flex: 1, height: 200 }}
        tweetId='788105828461006848'/>
      // this component is not displayed
       <Tweet
        style={{ flex: 1 }}
        tweetId='788105828461006848'/>
    </ScrollView>   
</View>

最佳答案

@smilledge 链接的 github 问题有答案。

当在 native 组件中动态添加 View 时,您似乎需要手动触发布局周期,以便 react native 接受更改。 (可能与 react native 更新其影 subview 有关)

 @Override
    public void requestLayout() {
        super.requestLayout();
        post(measureAndLayout);
    }

    private final Runnable measureAndLayout = new Runnable() {
        @Override
        public void run() {
            measure(
                    MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.EXACTLY),
                    MeasureSpec.makeMeasureSpec(getHeight(), MeasureSpec.EXACTLY));
            layout(getLeft(), getTop(), getRight(), getBottom());
        }
    };

关于ios - React Native自定义组件不会动态设置组件的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40291150/

相关文章:

ios - 更改图像图钉图

ios - 让我的字体作为 "fall-back"工作而不调用它

react-native - 有没有办法使用 Expo Image Picker 获取图像文件的原始名称?

react-native - react native : View onPress does not work

ios - "This app relies on Fabric"使用 CocoaPod 安装 fabric

ios - 如何在iOS中设置自定义属性?

iphone - 是否有一个很好的库来替代 UIAlertView

css - 我怎样才能使这个容器作为页脚出现在屏幕上,并使用 React Native 中的 css?

ios - Fabric 回答事件 : Total Count for Category Attribute

ios - 没有来自 TestFlight Beta 版本和 AppStore 的 Crashlytics 日志