【问题标题】:Can you do transitions in react-native with either inline styles or styled components您可以使用内联样式或样式化组件在 react-native 中进行转换吗
【发布时间】:2017-07-15 05:19:24
【问题描述】:

是否可以使用 StyleSheet 或 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 (
      <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'
  }
});

【问题讨论】:

    标签: javascript react-native styled-components


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2021-09-06
      • 1970-01-01
      • 1970-01-01
      • 2017-07-19
      • 1970-01-01
      • 2020-09-26
      • 1970-01-01
      • 2023-03-13
      • 2017-01-13
      相关资源
      最近更新 更多