Skip to content

Commit

Permalink
Merge pull request #657 from lovegaoshi/dev
Browse files Browse the repository at this point in the history
fix: artwork carousel
  • Loading branch information
lovegaoshi authored Nov 19, 2024
2 parents a91b9cf + 8738115 commit 8073ccb
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 8 deletions.
14 changes: 13 additions & 1 deletion src/components/commonui/HorizontalCarousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ interface Props {
paddingVertical?: number;
callback?: (direction: number, prevIndex: number) => void;
active?: boolean;
throttle?: boolean;
}

/**
Expand All @@ -43,10 +44,12 @@ export default ({
paddingVertical = 0,
callback = () => undefined,
active = true,
throttle = true,
}: Props) => {
// this number is contrained to 0, 1, 2
const carouselIndex = useSharedValue(1);
const [mImages, setMImages] = useState(images);
const [throttling, setThrottling] = useState(false);

const imgWidth = (imgStyle?.width as number) + paddingVertical;
const defaultGetImgSource = (i: number, arr = images) => arr[i];
Expand All @@ -55,6 +58,12 @@ export default ({
const activeCarouselTX = useSharedValue(0);
const carouselXs = useSharedValue([-imgWidth, 0, imgWidth]);

const toggleThrottle = (to = true) => {
if (throttle) {
setThrottling(to);
}
};

const snapToCarousel = () => {
'worklet';
if (Math.abs(activeCarouselTX.value) > imgWidth * 0.2) {
Expand All @@ -72,6 +81,7 @@ export default ({
return v;
});
runOnJS(callback)(direction, prevIndex);
runOnJS(toggleThrottle)(true);
},
);
return;
Expand All @@ -82,7 +92,7 @@ export default ({
const scrollDragGesture = useMemo(
() =>
Gesture.Pan()
.enabled(active)
.enabled(active && !throttling)
// swipe left and right
.activeOffsetX([-5, 5])
.failOffsetY([-5, 5])
Expand Down Expand Up @@ -127,6 +137,8 @@ export default ({
newImages[incIndex(carouselIndex.value, 3)] = images[2];
newImages[incIndex(carouselIndex.value, 3, false)] = images[0];
setMImages(newImages);
toggleThrottle(false);
console.log('APM', newImages);
}, [images]);

return (
Expand Down
2 changes: 1 addition & 1 deletion src/components/miniplayer/Artwork.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export default ({ miniplayerHeight, opacity, onPress, expand }: Props) => {
const refreshImageCarousel = () =>
setTrackCarousel([
{ uri: playNextSong(-1, false)?.cover },
{ uri: track?.song?.cover },
img,
{ uri: playNextSong(1, false)?.cover },
]);

Expand Down
10 changes: 5 additions & 5 deletions src/components/playlists/Playlists.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export default () => {
backgroundColor:
currentPlaylist.id === item
? // this is a special high contrast color than primaryContainer.
(playerStyle.customColors.playlistDrawerBackgroundColor ??
(playerStyle.customColors.playlistDrawerBackgroundColor ??
playerStyle.colors.primaryContainer)
: undefined,
},
Expand Down Expand Up @@ -150,9 +150,9 @@ export default () => {
{
backgroundColor:
currentPlaylist.id ===
playlists[StorageKeys.SEARCH_PLAYLIST_KEY]?.id
playlists[StorageKeys.SEARCH_PLAYLIST_KEY]?.id
? // this is a special high contrast color than primaryContainer.
(playerStyle.customColors.playlistDrawerBackgroundColor ??
(playerStyle.customColors.playlistDrawerBackgroundColor ??
playerStyle.colors.primaryContainer)
: undefined,
},
Expand All @@ -167,7 +167,7 @@ export default () => {
}
leadColor={
currentPlayingList.id ===
playlists[StorageKeys.SEARCH_PLAYLIST_KEY].id
playlists[StorageKeys.SEARCH_PLAYLIST_KEY].id
? playerStyle.colors.primary
: undefined
}
Expand All @@ -183,7 +183,7 @@ export default () => {
<FlashDragList
data={playlistIds}
renderItem={renderItem}
itemsSize={50}
itemsSize={53}
onSort={(fromIndex, toIndex) => {
const copy = [...playlistIds];
const removed = copy.splice(fromIndex, 1);
Expand Down
3 changes: 3 additions & 0 deletions src/hooks/useVIP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import { useEffect } from 'react';
import Purchases from 'react-native-purchases';
import { create } from 'zustand';
import { Purchases as PurchasesWeb } from '@revenuecat/purchases-js';
import i18n from 'i18next';

import { isAndroid } from '@utils/RNUtils';
import { getUser, getHasGuard } from '@utils/Bilibili/BiliUser';
// eslint-disable-next-line import/no-unresolved
import { APPSTORE, REVENUECAT_GOOGLE, REVENUECAT_STRIPE } from '@env';
import logger from '@utils/Logger';
import { setSnackMsg } from '@stores/useSnack';

const VIPKey = 'APMVIP';
const VIPId = 'apm-pro';
Expand All @@ -25,6 +27,7 @@ const initRevenueCatWeb = async (userid?: string) => {
const mUserid = userid ?? (await getUser()).mid;
if (mUserid === undefined) {
logger.error('[initRevenueCatWeb] mid is undefined');
setSnackMsg(i18n.t('Billing.MustLoginBilibili'));
throw new Error('[initRevenueCatWeb] mid is undefined');
}
isRevenueCatInitialized = true;
Expand Down
9 changes: 8 additions & 1 deletion src/stores/useSnack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export enum SnackType {
Processing = 'processing',
}

export default create<NoxSnack>((set, get) => ({
const useSnack = create<NoxSnack>((set, get) => ({
snackMsg: 'The quick brown fox jumps over the lazy dog.',
snackVisible: false,
snackType: SnackType.Success,
Expand Down Expand Up @@ -97,3 +97,10 @@ export default create<NoxSnack>((set, get) => ({
});
},
}));

export const setSnackMsg = (msg: string) =>
useSnack.getState().setSnack({
snackMsg: { success: msg },
});

export default useSnack;

0 comments on commit 8073ccb

Please sign in to comment.