Colors, Typography or Spacings return undefined in StyleSheet
Open
@ethanshar is already working on this.
Since Mar 16, 2022.
bug
- Dominant language
- TypeScript
- Stars
- 7.2k
- Forks
- 748
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 1
Description
Description
Colors, Typography, Spacings cannot be used in StyleSheet.create() [Forked from #1513]
Related to
- Components
- Demo
- Docs
- Typings
- Foundation
Steps to reproduce
Initialize any RN App. Put Colors.loadColors({...}) in entry file where App Component is registered.
In any component file, use
const styles = StyleSheet.create({
container: {
backgroundColor: Colors.customColor //returns undefined
}
})
Expected behavior
Any Colors property should return a HEX value. Example: Colors.customColor => "#374FE8"
Actual behavior
If you do not initialize StyleSheet.create() within the component (which is pointless) then Color values are not loaded properly.
Returns undefined.
More Info
Can provide if requested.
Code snippet
// entry file index.js
import { registerRootComponent } from "expo";
import { Colors } from "react-native-ui-lib";
import App from "./App.jsx";
Colors.loadColors({
customColor: "#374FE8"
});
registerRootComponent(App);
import { View, Text, Colors} from 'react-native-ui-lib'
const Home = (props) => {
// Will render a View with white background instead of 'customColor'
return (
<View style={styles.container}>
<Text>Home</Text>
</View>
)
}
const styles = StyleSheet.create({
container: {
backgroundColor: Colors.customColor
}
})
Screenshots/Video
No screenshots are available at this time.
Environment
// package.json
"dependencies": {
"expo": "~44.0.0",
"expo-splash-screen": "^0.14.1",
"expo-status-bar": "~1.2.0",
"react": "17.0.1",
"react-dom": "17.0.1",
"react-native": "0.64.3",
"react-native-gesture-handler": "^2.1.1",
"react-native-keyboard-aware-scroll-view": "^0.9.5",
"react-native-reanimated": "^2.3.1",
"react-native-ui-lib": "^6.7.1",
"react-native-vector-icons": "^9.0.0",
"react-native-web": "0.17.1",
"react-redux": "^7.2.6",
"react-router-dom": "^5.2.0",
"react-router-native": "^5.2.0",
"redux": "^4.1.2"
},
"devDependencies": {
"@babel/core": "^7.12.9",
"redux-devtools-extension": "^2.13.9"
},
- React Native: 0.64.3
- React Native UI Lib: ^6.7.1
Affected platforms
- Android
- iOS
- Web (untested)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.