Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rn): 修复 previewImage 时,点击 Android 虚拟导航键触发底部页面返回的问题 #10175

Merged
merged 6 commits into from
Sep 3, 2021
9 changes: 8 additions & 1 deletion packages/taro-rn/src/lib/previewImage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { View, ActivityIndicator, StyleSheet, Alert } from 'react-native'
import { View, ActivityIndicator, StyleSheet, Alert, BackHandler } from 'react-native'
import RootSiblings from 'react-native-root-siblings'
import ImageViewer from 'react-native-image-zoom-viewer'
import { saveMedia } from '../media'
Expand Down Expand Up @@ -28,8 +28,14 @@ export function previewImage(obj: Taro.previewImage.Option): void {
if (index === -1) {
throw new Error('"current" or "urls" is invalid')
}

let sibling
function backhandler() {
return true
}

function onSwipeDown() {
BackHandler.removeEventListener('hardwareBackPress', backhandler)
sibling?.destroy()
sibling = undefined
}
Expand Down Expand Up @@ -113,6 +119,7 @@ export function previewImage(obj: Taro.previewImage.Option): void {
/>
</View>
)
BackHandler.addEventListener('hardwareBackPress', backhandler)
} catch (e) {
onFail(e)
}
Expand Down