From b07db55573160c7d36a924775c42ecfa599c1136 Mon Sep 17 00:00:00 2001 From: Zhiyuan Zheng Date: Tue, 23 Mar 2021 23:16:01 +0100 Subject: [PATCH] Fixes --- src/Screens.tsx | 7 ++- src/components/Header/Right.tsx | 2 +- .../Timeline/Shared/Attachment/Audio.tsx | 60 ++++++++++--------- src/screens/ImagesViewer.tsx | 49 ++++++++------- src/screens/Tabs/Me/Push.tsx | 6 +- src/utils/slices/instancesSlice.ts | 11 ++++ 6 files changed, 81 insertions(+), 54 deletions(-) diff --git a/src/Screens.tsx b/src/Screens.tsx index f5c9c232..c156b45a 100644 --- a/src/Screens.tsx +++ b/src/Screens.tsx @@ -119,6 +119,8 @@ const Screens: React.FC = ({ localCorrupt }) => { routeRef.current = { name: currentRoute?.name, params: currentRoute?.params + ? JSON.stringify(currentRoute.params) + : undefined } }, []) const navigationContainerOnStateChange = useCallback(() => { @@ -144,7 +146,10 @@ const Screens: React.FC = ({ localCorrupt }) => { return ( <> - + = ({ : undefined, minHeight: 44, minWidth: 44, - marginLeft: native + marginRight: native ? -StyleConstants.Spacing.S : StyleConstants.Spacing.S, ...(type === 'icon' && { diff --git a/src/components/Timeline/Shared/Attachment/Audio.tsx b/src/components/Timeline/Shared/Attachment/Audio.tsx index cc904d72..227666e8 100644 --- a/src/components/Timeline/Shared/Attachment/Audio.tsx +++ b/src/components/Timeline/Shared/Attachment/Audio.tsx @@ -95,35 +95,37 @@ const AttachmentAudio: React.FC = ({ )} - - { - // audioPlayer?.pauseAsync() - // setAudioPlaying(false) - // }} - // onSlidingComplete={value => { - // setAudioPosition(value) - // }} - enabled={false} // Bug in above sliding actions - thumbSize={StyleConstants.Spacing.M} - thumbTintColor={theme.primaryOverlay} - /> - + {audio.meta.original.duration ? ( + + { + // audioPlayer?.pauseAsync() + // setAudioPlaying(false) + // }} + // onSlidingComplete={value => { + // setAudioPosition(value) + // }} + enabled={false} // Bug in above sliding actions + thumbSize={StyleConstants.Spacing.M} + thumbTintColor={theme.primaryOverlay} + /> + + ) : null} ) } diff --git a/src/screens/ImagesViewer.tsx b/src/screens/ImagesViewer.tsx index e093ea29..1561f536 100644 --- a/src/screens/ImagesViewer.tsx +++ b/src/screens/ImagesViewer.tsx @@ -23,32 +23,35 @@ import ImageViewer from './ImageViewer/Root' const saveImage = async ( image: Nav.RootStackParamList['Screen-ImagesViewer']['imageUrls'][0] ) => { - const hasAndroidPermission = async () => { - const permission = PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE + if (Platform.OS === 'ios') { + CameraRoll.save(image.url) + .then(() => haptics('Success')) + .catch(() => { + if (image.remote_url) { + CameraRoll.save(image.remote_url) + .then(() => haptics('Success')) + .catch(() => haptics('Error')) + } else { + haptics('Error') + } + }) + } else if (Platform.OS === 'android') { + const hasAndroidPermission = async () => { + const permission = PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE - const hasPermission = await PermissionsAndroid.check(permission) - if (hasPermission) { - return true + const hasPermission = await PermissionsAndroid.check(permission) + if (hasPermission) { + return true + } + + const status = await PermissionsAndroid.request(permission) + return status === 'granted' } - const status = await PermissionsAndroid.request(permission) - return status === 'granted' + if (!(await hasAndroidPermission())) { + return + } } - - if (Platform.OS === 'android' && !(await hasAndroidPermission())) { - return - } - CameraRoll.save(image.url) - .then(() => haptics('Success')) - .catch(() => { - if (image.remote_url) { - CameraRoll.save(image.remote_url) - .then(() => haptics('Success')) - .catch(() => haptics('Error')) - } else { - haptics('Error') - } - }) } const HeaderComponent = React.memo( @@ -109,6 +112,7 @@ const HeaderComponent = React.memo( navigation.goBack()} /> diff --git a/src/screens/Tabs/Me/Push.tsx b/src/screens/Tabs/Me/Push.tsx index 194b5b22..5e49be1b 100644 --- a/src/screens/Tabs/Me/Push.tsx +++ b/src/screens/Tabs/Me/Push.tsx @@ -2,7 +2,7 @@ import { MenuContainer, MenuRow } from '@components/Menu' import { updateInstancePush } from '@utils/slices/instances/updatePush' import { updateInstancePushAlert } from '@utils/slices/instances/updatePushAlert' import { updateInstancePushDecode } from '@utils/slices/instances/updatePushDecode' -import { getInstancePush } from '@utils/slices/instancesSlice' +import { clearPushLoading, getInstancePush } from '@utils/slices/instancesSlice' import * as WebBrowser from 'expo-web-browser' import * as Notifications from 'expo-notifications' import React, { useEffect, useMemo, useState } from 'react' @@ -36,6 +36,10 @@ const ScreenMeSettingsPush: React.FC = () => { } }, []) + useEffect(() => { + dispatch(clearPushLoading()) + }, []) + const isLoading = instancePush?.global.loading || instancePush?.decode.loading const alerts = useMemo(() => { diff --git a/src/utils/slices/instancesSlice.ts b/src/utils/slices/instancesSlice.ts index 46729b1f..9a52c899 100644 --- a/src/utils/slices/instancesSlice.ts +++ b/src/utils/slices/instancesSlice.ts @@ -164,6 +164,16 @@ const instancesSlice = createSlice({ draft => draft.timestamp !== action.payload ) }, + clearPushLoading: ({ instances }) => { + const activeIndex = findInstanceActive(instances) + instances[activeIndex].push.global.loading = false + instances[activeIndex].push.decode.loading = false + instances[activeIndex].push.alerts.favourite.loading = false + instances[activeIndex].push.alerts.follow.loading = false + instances[activeIndex].push.alerts.mention.loading = false + instances[activeIndex].push.alerts.poll.loading = false + instances[activeIndex].push.alerts.reblog.loading = false + }, disableAllPushes: ({ instances }) => { instances = instances.map(instance => { let newInstance = instance @@ -352,6 +362,7 @@ export const { updateInstanceNotificationsFilter, updateInstanceDraft, removeInstanceDraft, + clearPushLoading, disableAllPushes } = instancesSlice.actions