Skip to content

Commit

Permalink
fix: 图片预览器无法返回
Browse files Browse the repository at this point in the history
  • Loading branch information
maotoumao committed Aug 6, 2024
1 parent 5353b47 commit 00ebdfd
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 40 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"@react-navigation/drawer": "^6.7.2",
"@react-navigation/native": "^6.1.18",
"@react-navigation/native-stack": "^6.11.0",
"@sayem314/react-native-keep-awake": "^1.2.4",
"@shopify/flash-list": "^1.7.0",
"axios": "^1.7.3",
"big-integer": "^1.6.52",
Expand All @@ -43,6 +42,7 @@
"deepmerge": "^4.3.1",
"expo": "^51.0.0",
"expo-file-system": "^17.0.1",
"expo-keep-awake": "^13.0.2",
"expo-splash-screen": "~0.27.5",
"he": "^1.2.0",
"immer": "^10.1.1",
Expand Down
27 changes: 16 additions & 11 deletions src/components/dialogs/components/editSheetDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import {ImgAsset} from '@/constants/assetsConst';
import {launchImageLibrary} from 'react-native-image-picker';
import pathConst from '@/constants/pathConst';
import Image from '@/components/base/image';
import {copyFile, exists, unlink} from 'react-native-fs';
import MusicSheet from '@/core/musicSheet';
import {addFileScheme, addRandomHash} from '@/utils/fileUtils';
import Toast from '@/utils/toast';
import {hideDialog} from '../useDialog';
import Dialog from './base';
import Input from '@/components/base/input';
import {fontSizeConst} from '@/constants/uiConst';
import {copyAsync, deleteAsync, getInfoAsync} from 'expo-file-system';

interface IEditSheetDetailProps {
musicSheet: IMusic.IMusicSheetItem;
Expand Down Expand Up @@ -55,18 +55,23 @@ export default function EditSheetDetailDialog(props: IEditSheetDetailProps) {
return;
}

let _coverImg = coverImg;
if (_coverImg && _coverImg !== musicSheet?.coverImg) {
_coverImg = addFileScheme(
`${pathConst.dataPath}sheet${
musicSheet.id
}${_coverImg.substring(_coverImg.lastIndexOf('.'))}`,
let newCoverImg = coverImg;
if (coverImg && coverImg !== musicSheet?.coverImg) {
newCoverImg = addFileScheme(
`${pathConst.dataPath}sheet${musicSheet.id}${coverImg.substring(
coverImg.lastIndexOf('.'),
)}`,
);
try {
if (await exists(_coverImg)) {
await unlink(_coverImg);
if ((await getInfoAsync(newCoverImg)).exists) {
await deleteAsync(newCoverImg, {
idempotent: true, // 报错时不抛异常
});
}
await copyFile(coverImg!, _coverImg);
await copyAsync({
from: coverImg,
to: newCoverImg,
});
} catch (e) {
console.log(e);
}
Expand All @@ -78,7 +83,7 @@ export default function EditSheetDetailDialog(props: IEditSheetDetailProps) {
// 更新歌单信息
MusicSheet.updateAndSaveSheet(musicSheet.id, {
basic: {
coverImg: _coverImg ? addRandomHash(_coverImg) : undefined,
coverImg: newCoverImg ? addRandomHash(newCoverImg) : undefined,
title: _title,
},
}).then(() => {
Expand Down
4 changes: 1 addition & 3 deletions src/components/imageViewer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ export function ImageViewComponent() {
const currentImgSrc = currentImgSrcState.useValue();

const orientation = useOrientation();
console.log('FFF');

useEffect(() => {
const backHandler = BackHandler.addEventListener(
'hardwareBackPress',
() => {
console.log('HI');
if (currentImgSrcState.getValue()) {
currentImgSrcState.setValue(null);
return true;
Expand All @@ -38,7 +36,7 @@ export function ImageViewComponent() {
return () => {
backHandler.remove();
};
}, []);
}, [currentImgSrc]);

return currentImgSrc ? (
<TouchableWithoutFeedback
Expand Down
4 changes: 2 additions & 2 deletions src/constants/commonConst.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Animated, {Easing} from 'react-native-reanimated';
import {Easing, EasingFunction} from 'react-native-reanimated';

export const internalSymbolKey = Symbol.for('$');
// 加入播放列表/歌单的时间
Expand Down Expand Up @@ -66,7 +66,7 @@ export enum EDeviceEvents {
REFRESH_LYRIC = 'refresh-lyric',
}

const ANIMATION_EASING: Animated.EasingFunction = Easing.out(Easing.exp);
const ANIMATION_EASING: EasingFunction = Easing.out(Easing.exp);
const ANIMATION_DURATION = 150;

const animationFast = {
Expand Down
12 changes: 0 additions & 12 deletions src/core/mediaMeta.old.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,6 @@ async function setup() {
try {
await migrate();
} catch {}
// const metaKeys = (await getStorage(StorageKeys.MediaMetaKeys)) ?? {};
// if (!metaKeys) {
// await setStorage(StorageKeys.MediaMetaKeys, {});
// }
// const kv: [string, string][] = Object.entries(metaKeys);
// const metas = await getMultiStorage(kv.map(_ => _[1]));
// const newMediaMetas: Record<string, Record<string, any>> = {};
// metas.forEach((value, index) => {
// newMediaMetas[kv[index][0]] = value ?? {};
// });
// mediaMetas = newMediaMetas;
// // // todo: setup时校验一下,清空冗余数据
}

async function migrate() {
Expand Down
7 changes: 2 additions & 5 deletions src/pages/musicDetail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,15 @@ import Content from './components/content';
import Lyric from './components/content/lyric';
import NavBar from './components/navBar';
import Config from '@/core/config';
import {
activateKeepAwake,
deactivateKeepAwake,
} from '@sayem314/react-native-keep-awake';
import {activateKeepAwakeAsync, deactivateKeepAwake} from 'expo-keep-awake';

export default function MusicDetail() {
const orientation = useOrientation();

useEffect(() => {
const needAwake = Config.get('setting.basic.musicDetailAwake');
if (needAwake) {
activateKeepAwake();
activateKeepAwakeAsync();
}
return () => {
if (needAwake) {
Expand Down
7 changes: 1 addition & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2759,11 +2759,6 @@
mkdirp "^1.0.4"
rimraf "^3.0.2"

"@sayem314/react-native-keep-awake@^1.2.4":
version "1.2.4"
resolved "https://registry.npmmirror.com/@sayem314/react-native-keep-awake/-/react-native-keep-awake-1.2.4.tgz#f7cfb21983c38042f484d2d768f7f41678b3dddc"
integrity sha512-I9tRpZ8z693lce4seDbRK0zBzeCkubBnSGmABiRPTRy2ZkMJB1m+vaXiDHl6U3fJa29i2TTaKclH3A8to/Bs9A==

"@segment/loosely-validate-event@^2.0.0":
version "2.0.0"
resolved "https://registry.npmmirror.com/@segment/loosely-validate-event/-/loosely-validate-event-2.0.0.tgz#87dfc979e5b4e7b82c5f1d8b722dfd5d77644681"
Expand Down Expand Up @@ -5328,7 +5323,7 @@ expo-font@~12.0.9:
dependencies:
fontfaceobserver "^2.1.0"

expo-keep-awake@~13.0.2:
expo-keep-awake@^13.0.2, expo-keep-awake@~13.0.2:
version "13.0.2"
resolved "https://registry.npmmirror.com/expo-keep-awake/-/expo-keep-awake-13.0.2.tgz#5ef31311a339671eec9921b934fdd90ab9652b0e"
integrity sha512-kKiwkVg/bY0AJ5q1Pxnm/GvpeB6hbNJhcFsoOWDh2NlpibhCLaHL826KHUM+WsnJRbVRxJ+K9vbPRHEMvFpVyw==
Expand Down

0 comments on commit 00ebdfd

Please sign in to comment.