Javascript 您可以使用内联样式或样式化组件在react native中进行转换吗
是否可以使用样式表或样式化组件在react native中进行转换?我正在尝试下面的方法,但运气不好Javascript 您可以使用内联样式或样式化组件在react native中进行转换吗,javascript,react-native,styled-components,Javascript,React Native,Styled Components,是否可以使用样式表或样式化组件在react native中进行转换?我正在尝试下面的方法,但运气不好 import React from 'react' import styled from 'styled-components/native' import { Text, View, StyleSheet } from 'react-native' export default class extends React.Component { render() { return (
import React from 'react'
import styled from 'styled-components/native'
import { Text, View, StyleSheet } from 'react-native'
export default class extends React.Component {
render() {
return (
<Wrapper visible={visible}><Text>hello</Text>
)
}
}
const Wrapper = styled.View`
opacity: ${props => props.visible ? 1 : 0};
transition: opacity 1s linear;
`
const styles = StyleSheet.create({
wrapper: {
opacity: 1,
transition:'opacity 1s linear'
}
});
从“React”导入React
从“样式化组件/本机”导入样式化
从“react native”导入{Text,View,StyleSheet}
导出默认类扩展React.Component{
render(){
返回(
你好
)
}
}
const Wrapper=styled.View`
不透明度:${props=>props.visible?1:0};
过渡:不透明度1s线性;
`
const styles=StyleSheet.create({
包装器:{
不透明度:1,
过渡:“不透明度1s线性”
}
});
React Native不支持以这种方式进行React样式转换,请尝试RN动画视图库,它的工作原理非常类似(并使用内联样式/组件):