4

是否可以使用 StyleSheet 或 styled-components 在本机反应中进行转换?我正在尝试以下没有运气。

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'
  }
});
4

1 回答 1

3

React Native 不支持这种方式的 react 样式转换,而是尝试使用 RN Animated View 库,它的工作方式非常相似(并且使用内联样式/组件):

https://facebook.github.io/react-native/docs/animated.html

于 2017-02-24T23:05:24.423 回答