无法在Animated.View上使用onPress()事件设置为Position:Absolute-React Native

时间:2020-10-05 02:52:14

标签: react-native css-position touchableopacity react-native-reanimated touchablehighlight

我为公司正在开发的应用程序制作了可滚动标题。当我尝试使用TouchableHighlight触发onPress()事件时,由于位置键设置为“绝对”,因此未注册:

经过数小时的上网搜索,我尝试了以下方法:

-提高zIndex /海拔 -确保从'react-native'导入TouchableHighlight -“ react-native-reanimated”动画库

当我注释掉主标头中的position:absolute时,它可以正常工作,但是当标头向上滚动时,标头会留下一个视图,使我无法在其顶部放置视图。

我这里的选项已用完...任何帮助将不胜感激!

     <Animated.View style={globalStyles.tabNavbar}>
          <TouchableHighlight
              style={{backgroundColor: 'white', height: 50, width: 100, zIndex: 99999, elevation: 99999}}
              underlayColor="#eee"
              onPress={() => {
                  console.log('PLZ WORK');
                  this.updateTabs('projectsTab');
          }}  >
              <Animated.View style={{ alignItems: 'center'}}>
                  <Text  onPress={() => { this.updateTabs('projectsTab');}} style={{fontWeight: 'bold'}}>Close</Text>
              </Animated.View>
          </TouchableHighlight>
          <TouchableHighlight
              style={{color: 'white'}}
              underlayColor="#eee"
              onPress={() => {
                  console.log('PLZ WORK');
                  this.updateTabs('notificationTab');
          }}  >
              <View style={{alignItems: 'center'}}>
                  <Text style={{fontWeight: 'bold'}}>Close</Text>
              </View>
          </TouchableHighlight>
      </Animated.View>

1 个答案:

答案 0 :(得分:0)

对于那些想知道的人,如果将“组件”的“查看”顺序更改为位置为“绝对”的组件的最后位置,则这些按钮将起作用。在这种情况下,即使标题出现在屏幕顶部,我也必须将标题排在最后。