android - showInAppNotification - 通知不会在 Android 上关闭
问题描述
我react-native-navigation
在我的应用程序上使用该库,但每当我尝试使用该showInAppNotification
方法添加通知时,通知不会按预期在滑动时消失。在 iOS 上通常可以通过滑动来关闭通知。有没有人遇到过这个问题?
重现步骤
showInAppNotification
1 - 使用以下方法添加通知:
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 - 调试模式
解决方案
在使用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,
},
});
推荐阅读
- apache-kafka - Kafka Stream 甚至在窗口关闭之前创建新的聚合
- arrays - 如何将 Minizinc 中的变量约束为集合的一部分
- python - 在反向代理 (traefik) 后面使用 phyton 的 http.server 时获取“404”
- f# - 如何使用 xUnit 测试 F# 选项类型
- sqlcmd - SQLCMD 实用程序:与第二个实例的连接不起作用
- python - 无法使用 popen 重定向 IO
- python - 带有验证的会话帖子在 python3.7.2 中不起作用
- c# - 如何使用 Entity Framework Core 和 Npgsql 清理我的所有字符串输入?
- python - 如何使用 Pandas 执行 first() 和 max() groupby 的等效(来自 SQL)?
- r - dplyr 函数 group_by 几个变量