Skip to content

Commit

Permalink
feat: 回退事件监听
Browse files Browse the repository at this point in the history
  • Loading branch information
maotoumao committed May 21, 2023
1 parent 3499559 commit 84f5e9b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "MusicFree",
"version": "0.1.0-alpha.6",
"version": "0.1.0-alpha.7",
"license": "GPL",
"private": true,
"author": {
Expand Down
21 changes: 19 additions & 2 deletions src/components/imageViewer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import React, {useEffect} from 'react';
import {
BackHandler,
Image,
StyleSheet,
TouchableOpacity,
Expand All @@ -21,6 +22,22 @@ export function ImageViewComponent() {

const orientation = useOrientation();

useEffect(() => {
const backHandler = BackHandler.addEventListener(
'hardwareBackPress',
() => {
if (currentImgSrcState.getValue()) {
currentImgSrcState.setValue(null);
return true;
}
return false;
},
);
return () => {
backHandler.remove();
};
}, []);

return currentImgSrc ? (
<TouchableWithoutFeedback
onPress={() => {
Expand Down Expand Up @@ -102,6 +119,6 @@ const style = StyleSheet.create({
paddingHorizontal: rpx(18),
paddingVertical: rpx(12),
borderRadius: rpx(8),
backgroundColor: '#20232a',
backgroundColor: '#20232a ',
},
});

0 comments on commit 84f5e9b

Please sign in to comment.