react-native - React Native : Why does stylesheet. 创建带有数字而不是样式的返回对象?

标签 react-native

我创建了样式,但有时我无法使用它们,因为它们返回数字:

const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: '#FFFFFF'
    },
    moodSliderContainer: {
        justifyContent: 'center',
        alignItems: 'center',
        width: '100%'
    },
    postListContainer: {
        width: '100%',
        height: '100%',
        paddingBottom: 120
    }
});
console.log(styles);

enter image description here

最佳答案

来自 React Native documentation - StyleSheet :

Performance:

  • Making a stylesheet from a style object makes it possible to refer to it by ID instead of creating a new style object every time.

  • It also allows to send the style only once through the bridge. All subsequent uses are going to refer an id (not implemented yet).



如果要检索实际样式对象,可以使用 StyleSheet.flatten(styles.container) .

关于react-native - React Native : Why does stylesheet. 创建带有数字而不是样式的返回对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49782275/

相关文章:

javascript - 为什么我得到 'Cannot read property ' push' of undefined' (React Native)?

java - 以编程方式访问 React Native 中的“主页”按钮

android - 如何使用 AsyncStorage React Native 缓存 API 数据

android - React Native - 在 Android 中显示传入的视频通话屏幕(VOIP 应用程序)

javascript - 将数组转换为对象以选择对象(重构/优化)

javascript - 状态数组中的更改元素不会触发 UI 更改

android - 如何从 Android 的自定义 react-native native 模块中制作 npm 包?

javascript - 未处理的 promise 拒绝: TypeError: undefined is not a function evaluating 'departureloc.map' occurs when mapping for setState in react native

gradle - React Native gradlew clean 命令不起作用

react-native - 如何在 react-native 中使用 fetch 发布 multipart/formdata?