首页 > 解决方案 > showInAppNotification - 通知不会在 Android 上关闭

问题描述

react-native-navigation在我的应用程序上使用该库,但每当我尝试使用该showInAppNotification方法添加通知时,通知不会按预期在滑动时消失。在 iOS 上通常可以通过滑动来关闭通知。有没有人遇到过这个问题?

重现步骤

showInAppNotification1 - 使用以下方法添加通知:

this.props.navigator.showInAppNotification({
    screen: "example.InAppNotification",
    passProps: { ...notificationProps },
    autoDismissTimerSec: 5,
  });

2 - 在 Android 设备上运行应用程序;
3 - 触发通知显示;
4 - 尝试向上滑动通知以关闭


环境

标签: androidreact-nativereact-native-navigation

解决方案


在使用react-native-swipe-gestures库和和LayoutAnimation.
这是解决方法的总体思路,以防有人在这里遇到同样的问题:

class MyNotification extends React.PureComponent {

   state = {
      isNotificationDismissed: false,
  };

  render() {
      return (
        <GestureRecognizer
          style={this.getDisplayStyle()}
          onSwipeUp={this.handleSwipeUp}>
          {this.renderNotificationContent()}
        </GestureRecognizer>
      );
    }

    getDisplayStyle = () => {
      if (this.state.isNotificationDismissed) return styles.hiddenNotification;
      return styles.visibleNotification;
    };

    handleSwipeUp = () => {
      LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);
      this.setState({ isNotificationDismissed: true });
    };

   . 
   .
   .
}

const styles = StyleSheet.create({
    visibleNotification: {
      height: 64,
    },
    hiddenNotification: {
      height: 0,
    },
});

推荐阅读