That function is not part of the library on react-native according to this Github issue. That's why it keeps saying that it's not a function, because it can't find it.
Answer from Noah Allen on Stack OverflowVideos
That function is not part of the library on react-native according to this Github issue. That's why it keeps saying that it's not a function, because it can't find it.
create a styles.js file like this:
import React, {Component} from 'react';
import {
Platform,
StyleSheet
} from 'react-native';
export const styles = StyleSheet.create({
view_flex_one_white: {
flex: 1,
backgroundColor: white
}});
and use this anywhere in your app with import
import {styles} from "...link to file/styles";
render(){
return(
<View style={styles.view_flex_one_white}>
</View>
)
}
You may create a reusable stylesheet. Example:
style.js
'use strict';
import { StyleSheet } from 'react-native';
module.exports = StyleSheet.create({
alwaysred: {
backgroundColor: 'red',
height: 100,
width: 100,
},
});
In your component:
const s = require('./style');
...then:
<View style={s.alwaysred} ></View>
Create a file for your styles (I.E., Style.js).
Here is an example:
import { StyleSheet } from 'react-native';
export default StyleSheet.create({
container: {
flex: 1
},
welcome: {
fontSize: 20
}
});
In any of the files you want to use your style, add the following:
import styles from './Style'
React native styling is based on js objects. So, you could create your "styling" objects on separate js files and import those files into your react components. Since sometimes it is a good idea to change the style of an object based on the values of a state variable then it could be great to have the needed values nearby for "fast understanding". All depends on how you organize your code. For example, the next code (from native tutorial) can be declared on a separate js file:
export const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
button: {
alignItems: 'center',
backgroundColor: '#DDDDDD',
padding: 10,
marginBottom: 10
}
})
and later import using an import command:
import {styles} from '.... path to file where you placed styles code ... "
If you dont want to use class inheritance, you can write HOC which can apply styles to its child. Inside the child component, inherit required property styles from parent. BaseStyle is the hoc, maintaining the css definitions for all components. On your component that needs to inherit, we need to wrap them with the BaseStyle by providing the required style prop.
function ComponentInheritingStyle() {
return (
<BaseStyle style={styles.button}>
{...this.props.children}
</BaseStyle>
);
}
export const styles = StyleSheet.create({
button: {
backgroundColor: 'blue',
fontSize: '12',
borderRadius: '4',
},
div: {
border: '2px',
borderColor: 'lightblue',
padding: 10,
marginBottom: 10
}
})
you could read the below link for better clarity, through class. Inheritance in React JS