繁体   English   中英

只能在Android上的对象上调用Object.freeze

[英]Getting Object.freeze can only be called on Objects on Android

我得到的Object.freeze只能在Objects调用 (仅限Android)。

经过深入研究后,我发现这是因为我在不同的文件夹中引用了我的所有样式,Android对此并不满意。

Github问题

图片

我的文件夹结构

  • SRC

    • 行动
    • 集装箱
      • Home.js(有风格)
    • 组件
    • 款式
      • calculateSize.js
      • index.js
  • App.js

  • Router.js(有风格)

正如你所看到的,模拟器开始抱怨

Router.js: 9

对应于

import styles from './styles'; // Line 9 in Router.js

长话短说,如果我在想要做样式的文件中创建本地StyleSheet变量非常烦人,问题就会消失。

以前有人遇到过这个吗? 我找不到解决方案:(

这是我的样式索引,也许某些方法呈现未定义,我不知道它

calculateSize

 import { Dimensions } from 'react-native'; const deviceWidth = Dimensions.get('window').width; const deviceHeight = Dimensions.get('window').height; // Calculating ratio from iPhone breakpoints export const ratioX = deviceWidth < 375 ? (deviceWidth < 320 ? 0.75 : 0.875) : 1 ; export const ratioY = deviceHeight < 568 ? (deviceHeight < 480 ? 0.75 : 0.875) : 1 ; // Set our base font size value const base_unit = 16; // Simulating EM by changing font size according to Ratio const unit = base_unit * ratioX; export default function em(value) { return (unit * value); } 

index.js

 import { Dimensions, StyleSheet, Platform } from 'react-native'; import em from './calculateSize'; const deviceWidth = Dimensions.get('window').width; const deviceHeight = Dimensions.get('window').height; export const colors = { gray: '#888888', }; export default StyleSheet.create({ // // STATICS // DEVICE_WIDTH: deviceWidth, DEVICE_HEIGHT: deviceHeight, RATIO_X: em.ratioX, RATIO_Y: em.ratioY, UNIT: em(1), PADDING: em(1.25), FONT_SIZE: em(1), FONT_SIZE_SMALLER: em(0.75), FONT_SIZE_SMALL: em(0.875), FONT_SIZE_TITLE: em(1.25), // // REACT-NATIVE-ROUTER-FLUX // navigationBarStyle: { backgroundColor: '#dd2c00', borderBottomWidth: 0, }, navTitleStyle: { color: 'white', }, navBarButton: { position: 'absolute', top: 10, }, navBarLeftButton: { left: 10 }, navBarrightButton: { right: 10 }, // // GENERALS // testShit: { borderColor: 'red', borderWidth: 2 }, centerEverything: { justifyContent: 'center', alignItems: 'center', }, authContainer: { flex: 1, paddingTop: 50, }, bitOfTransparent: { backgroundColor: 'rgba(0,0,0,.5)' }, // // AUTHS // spanImage: { height: deviceHeight, width: deviceWidth, }, statusBarSpan: { width: deviceWidth, flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', top: 20, paddingLeft: 15, paddingRight: 15, position: 'absolute' }, residentValetUpperContainer: { flex: .25, width: deviceWidth*0.8 }, residentValetBottomContainer: { flex: .75, width: deviceWidth, alignItems: 'center', justifyContent: 'flex-end', paddingBottom: 20 }, residentValetBottomContainerField: { justifyContent: 'flex-start' }, residentValetText: { fontSize: em(1)*1.5, letterSpacing: 10, textAlign: 'center', color: '#fff', backgroundColor: 'transparent', }, residentValetDesc: { fontSize: em(1)*1.25, letterSpacing: 0, flexWrap: 'wrap' }, helLight: { fontFamily: 'HelveticaNeue-Light', }, loginButton: { flexDirection: 'row', width: deviceWidth*0.9, height: 50, backgroundColor: 'transparent', borderColor: '#fff', borderWidth: 1, borderRadius: 3, }, loginButtonText: { fontSize: em(1), color: '#fff', paddingLeft: 10, }, policyText: { fontSize: em(0.85), color: '#fff', backgroundColor: 'transparent' }, nextButtonText: { fontSize: em(1.25), fontWeight: '500', backgroundColor: 'transparent' }, container: { flex: 1, ...Platform.select({ ios: { marginTop: 64 }, android: { paddingTop: 54 } }) } }) 

该错误是由于您在StyleSheet.create调用中具有的非对象属性,即 -

//
// STATICS
//
DEVICE_WIDTH: deviceWidth,
DEVICE_HEIGHT: deviceHeight,
RATIO_X: em.ratioX,
RATIO_Y: em.ratioY,
UNIT: em(1),
PADDING: em(1.25),

FONT_SIZE: em(1),
FONT_SIZE_SMALLER: em(0.75),
FONT_SIZE_SMALL: em(0.875),
FONT_SIZE_TITLE: em(1.25),

StyleSheet.create仅支持样式对象,不支持任何随机属性。

您只能在Android中获得错误,因为不同版本的JSC之间的实现存在差异。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM