【问题标题】:React native: How to move Input from center to top with animation?React native:如何使用动画将输入从中心移动到顶部?
【发布时间】:2017-01-20 09:43:35
【问题描述】:

我正在尝试创建一个输入,当用户开始输入一些文本时,它将从中心移动到顶部。如何通过动画将justifyContent: 'center' 更改为justifyContent: 'flex-start'?或者也许我应该以其他方式来做?

我的代码:

<View style={styles.container}>
  <SearchInput
    onChangeText={this.handleInputChange}
  />
</View>

和样式:

const styles = {
  container: {
    flex: 1,
    alignItems: 'stretch',
    justifyContent: 'center',
    flexDirection: 'column'
  }
};

【问题讨论】:

标签: javascript react-native flexbox


【解决方案1】:

您应该可以使用LayoutAnimation免费实现这一目标。

这就是你要做的,显然有些事情被遗漏了:

handleFocus = () => {
  LayoutAnimation.easeInEaseOut();
  this.setState({
    isSearching: true,
  });
};

render() {
  const style = {
    justifyContent: this.state.isSearching
      ? 'flex-start'
      : 'center',
  };
  return (
    <TextInput onFocus={this.handleFocus} style={style} />
  );
}

如果这不起作用,我怀疑,你将不得不使用Animated

【讨论】:

  • 这是个好主意,而动画插值不能传输字符串值。 (y)
猜你喜欢
  • 2023-03-23
  • 2018-10-30
  • 2013-10-09
  • 2019-08-15
  • 1970-01-01
  • 1970-01-01
  • 2021-08-06
  • 2019-06-03
  • 2012-06-01
相关资源
最近更新 更多