Performance 预构建“重”组件?

Performance 预构建“重”组件?,performance,react-native,components,Performance,React Native,Components,我有一个组件,一个自定义键盘,在React Native中显示/构建大约需要1秒 是否可以预构建此组件(例如在启动时),并在需要显示时立即显示它?唯一的方法是提前渲染它。通过在屏幕外使用零不透明度或translateX进行渲染,并通过更改这些属性使其可见,可以轻松做到这一点 例如: const styles = StyleSheet.create({ invisible: { opacity: 0, transform: [ {tr

我有一个组件,一个自定义键盘,在React Native中显示/构建大约需要1秒


是否可以预构建此组件(例如在启动时),并在需要显示时立即显示它?

唯一的方法是提前渲染它。通过在屏幕外使用零不透明度或translateX进行渲染,并通过更改这些属性使其可见,可以轻松做到这一点

例如:

const styles = StyleSheet.create({
    invisible: {
        opacity: 0,
        transform: [
            {translateX: -3000}
        ]
    }
})

const MyHeavyComponent = ({isVisible, ...props}) => {
    const visiblityStyle = isVisible ? null : styles.invisible;

    return (
        <View style={visiblityStyle}>
            ...
        </View>
    )
}

谢谢,我一定会这么做的。