android - 带有滚动动画标题的选项卡 - React native

标签 android ios animation react-native

我正在按照链接中的教程进行操作:https://medium.com/appandflow/react-native-scrollview-animated-header-10a18cb9469e . 但是,我似乎无法理解如何向其中添加选项卡,以便选项卡标题在向上滚动时固定到顶部。谁能建议如何实现这一目标?

最佳答案

我能够使用 native 库中的 ScrollableTab 和 Tab 来实现它。

代码是这样的

<Tabs
  prerenderingSiblingsNumber={3}
  onChangeTab={({ i }) => {
    this.setState({ height: this.heights[i], activeTab: i })
  }}
  renderTabBar={(props) => (
    <Animated.View style={{ transform: [{ translateY: tabY }], zIndex: 1, width: "100%", backgroundColor: "white", paddingTop: HEADER_MAX_HEIGHT }}>
      <ScrollableTab 
        {...props}
        renderTab={(name, page, active, onPress, onLayout) => (
          <TouchableOpacity key={page}
            onPress={() => onPress(page)}
            onLayout={onLayout}
            activeOpacity={0.4}>
            <Animated.View
              style={{
                flex: 1,
                height: 100,
                backgroundColor: tabBg
              }}>
              <TabHeading scrollable
                style={{
                  backgroundColor: "transparent",
                  width: Dimensions.get('window').width / 2
                }}
                active={active}>
                <Animated.Text style={{
                  fontWeight: active ? "bold" : "normal",
                  color: 'black',
                  padding: 10,
                  fontSize: active ? 20 : 18
                }}>
                  {name}
                </Animated.Text>
              </TabHeading>
            </Animated.View>
          </TouchableOpacity>
        )}
        underlineStyle={{ backgroundColor: 'black' }} 
      />
    </Animated.View>
  )}>
  <Tab heading="Tab 1">
    {this.tabContent(30, 0)}
  </Tab>
  <Tab heading="Tab 2">
    {this.tabContent(15, 1)}
  </Tab>
</Tabs>

关于android - 带有滚动动画标题的选项卡 - React native,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50650635/

相关文章:

Android 无法从 ListView 行中按钮的 onClick 找到方法

iphone - 为 iPad 设置图标,应用程序的目标设备是 iPhone

ios - Swift 是 "porting iOS app to OSX"的解决方案吗?

ios - Siri 快捷方式自定义响应没有扩展名?

html - 图像在屏幕上滑动 - CSS3

ios - 按钮启动的UIImage动画

java - Android Studio & libGDX - android.os.* 无法实现(所有 android 都无法实现)

android - 使用 vuforia qualcomm 播放动画图像

android - 无法构建应用,错误TaskExecutionException:app:compileDebugJavaWithJavac,gradle 3.1.0

c# - 等待动画在 unity3d 中完成