【问题标题】:showInAppNotification - notification does not dismiss on AndroidshowInAppNotification - 通知不会在 Android 上关闭
【发布时间】:2018-07-23 17:17:36
【问题描述】:

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

复制步骤

1 - 使用showInAppNotification 方法添加通知:

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

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


环境

  • React Native Navigation 版本:1.1.433
  • React Native 版本:0.55.4
  • 平台:安卓
  • 设备信息:SM-G950F - 8.0.0 - 调试模式

【问题讨论】:

    标签: android react-native react-native-navigation


    【解决方案1】:

    使用react-native-swipe-gestures 库和LayoutAnimation 在Android 上获得滑动关闭。
    以下是解决方法的总体思路,以防有人在这里遇到同样的问题:

    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,
        },
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-11-22
      • 2014-02-25
      • 1970-01-01
      • 2016-04-17
      • 1970-01-01
      • 1970-01-01
      • 2021-03-08
      相关资源
      最近更新 更多