Skip to content

Commit

Permalink
Merge pull request #634 from lovegaoshi/dev
Browse files Browse the repository at this point in the history
fix: color
  • Loading branch information
lovegaoshi authored Nov 12, 2024
2 parents 1453ebb + 0eaf8aa commit d8f92e1
Show file tree
Hide file tree
Showing 16 changed files with 170 additions and 38 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"editor.formatOnSave": true,
"search.exclude": {
"MusicFreePlugins": true
}
},
"editor.tabSize": 2
}
90 changes: 90 additions & 0 deletions patches/react-native-draggable-flatlist+4.0.1.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
diff --git a/node_modules/react-native-draggable-flatlist/src/components/DraggableFlatList.tsx b/node_modules/react-native-draggable-flatlist/src/components/DraggableFlatList.tsx
index d7d98c2..2f59c7a 100644
--- a/node_modules/react-native-draggable-flatlist/src/components/DraggableFlatList.tsx
+++ b/node_modules/react-native-draggable-flatlist/src/components/DraggableFlatList.tsx
@@ -295,7 +295,7 @@ function DraggableFlatListInner<T>(props: DraggableFlatListProps<T>) {
const springTo = placeholderOffset.value - activeCellOffset.value;
touchTranslate.value = withSpring(
springTo,
- animationConfigRef.current,
+ animationConfigRef.value,
() => {
runOnJS(onDragEnd)({
from: activeIndexAnim.value,
diff --git a/node_modules/react-native-draggable-flatlist/src/context/refContext.tsx b/node_modules/react-native-draggable-flatlist/src/context/refContext.tsx
index ea21575..66c5eed 100644
--- a/node_modules/react-native-draggable-flatlist/src/context/refContext.tsx
+++ b/node_modules/react-native-draggable-flatlist/src/context/refContext.tsx
@@ -1,14 +1,14 @@
import React, { useContext } from "react";
import { useMemo, useRef } from "react";
import { FlatList } from "react-native-gesture-handler";
-import Animated, { WithSpringConfig } from "react-native-reanimated";
+import Animated, { type SharedValue, useSharedValue, WithSpringConfig } from "react-native-reanimated";
import { DEFAULT_PROPS } from "../constants";
import { useProps } from "./propsContext";
import { CellData, DraggableFlatListProps } from "../types";

type RefContextValue<T> = {
propsRef: React.MutableRefObject<DraggableFlatListProps<T>>;
- animationConfigRef: React.MutableRefObject<WithSpringConfig>;
+ animationConfigRef: SharedValue<WithSpringConfig>;
cellDataRef: React.MutableRefObject<Map<string, CellData>>;
keyToIndexRef: React.MutableRefObject<Map<string, number>>;
containerRef: React.RefObject<Animated.View>;
@@ -54,8 +54,8 @@ function useSetupRefs<T>({
...DEFAULT_PROPS.animationConfig,
...animationConfig,
} as WithSpringConfig;
- const animationConfigRef = useRef(animConfig);
- animationConfigRef.current = animConfig;
+ const animationConfigRef = useSharedValue(animConfig);
+ animationConfigRef.value = animConfig;

const cellDataRef = useRef(new Map<string, CellData>());
const keyToIndexRef = useRef(new Map<string, number>());
diff --git a/node_modules/react-native-draggable-flatlist/src/hooks/useCellTranslate.tsx b/node_modules/react-native-draggable-flatlist/src/hooks/useCellTranslate.tsx
index ce4ab68..efea240 100644
--- a/node_modules/react-native-draggable-flatlist/src/hooks/useCellTranslate.tsx
+++ b/node_modules/react-native-draggable-flatlist/src/hooks/useCellTranslate.tsx
@@ -101,7 +101,7 @@ export function useCellTranslate({ cellIndex, cellSize, cellOffset }: Params) {
? activeCellSize.value * (isAfterActive ? -1 : 1)
: 0;

- return withSpring(translationAmt, animationConfigRef.current);
+ return withSpring(translationAmt, animationConfigRef.value);
}, [activeKey, cellIndex]);

return translate;
diff --git a/node_modules/react-native-draggable-flatlist/src/hooks/useOnCellActiveAnimation.ts b/node_modules/react-native-draggable-flatlist/src/hooks/useOnCellActiveAnimation.ts
index 7c20587..cfc6a4f 100644
--- a/node_modules/react-native-draggable-flatlist/src/hooks/useOnCellActiveAnimation.ts
+++ b/node_modules/react-native-draggable-flatlist/src/hooks/useOnCellActiveAnimation.ts
@@ -1,6 +1,7 @@
import { useRef } from "react";
import Animated, {
useDerivedValue,
+ useSharedValue,
withSpring,
WithSpringConfig,
} from "react-native-reanimated";
@@ -15,8 +16,8 @@ type Params = {
export function useOnCellActiveAnimation(
{ animationConfig }: Params = { animationConfig: {} }
) {
- const animationConfigRef = useRef(animationConfig);
- animationConfigRef.current = animationConfig;
+ const animationConfigRef = useSharedValue(animationConfig);
+ animationConfigRef.value = animationConfig;

const isActive = useIsActive();

@@ -26,7 +27,7 @@ export function useOnCellActiveAnimation(
const toVal = isActive && isTouchActiveNative.value ? 1 : 0;
return withSpring(toVal, {
...DEFAULT_ANIMATION_CONFIG,
- ...animationConfigRef.current,
+ ...animationConfigRef.value,
});
}, [isActive]);

17 changes: 0 additions & 17 deletions patches/react-native-reanimated+3.16.1.patch

This file was deleted.

8 changes: 6 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import MainBackground from './components/background/MainBackground';
import useTheme from './hooks/useTheme';
// eslint-disable-next-line import/no-unresolved
import { TRACKING } from '@env';
import useVIP from './hooks/useVIP';

if (TRACKING) {
Sentry.init({
Expand Down Expand Up @@ -53,9 +54,12 @@ const APM = ({ PIP, isLandscape }: { PIP: boolean; isLandscape: boolean }) => {
};

export default function App(appProps: NoxComponent.AppProps) {
const isSplashReady = useSplash(__DEV__ || appProps.intentData ? 1 : 2500);
const { vip } = useVIP();
const isSplashReady = useSplash(
__DEV__ || appProps.intentData || vip ? 1 : 2500,
);
const [isSplashAnimReady, setIsSplashReady] = React.useState(false);
const isPlayerReady = useSetupPlayer(appProps);
const isPlayerReady = useSetupPlayer({ ...appProps, vip });
const isLandscape = useIsLandscape();
const PIPMode = useStore(appStore, state => state.pipMode);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down
1 change: 0 additions & 1 deletion src/AzusaPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ interface Props extends NoxComponent.NavigationProps {
}
const NoxPlayer = ({ navigation, setNavigation = () => undefined }: Props) => {
const Tab = createMaterialTopTabNavigator();

useEffect(() => setNavigation(navigation), []);

return (
Expand Down
4 changes: 4 additions & 0 deletions src/components/billing/bill.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { getHasGuard } from '@utils/Bilibili/BiliUser';

//暗精灵和小孩梓尊享APM VIP服务
const getBiliVIPStatus = () => getHasGuard([529249, 7706705]);
8 changes: 4 additions & 4 deletions src/components/playlists/Playlists.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ export default () => {
backgroundColor:
currentPlaylist.id === item
? // this is a special high contrast color than primaryContainer.
(playerStyle.colors.playlistDrawerBackgroundColor ??
playerStyle.customColors.primaryContainer)
(playerStyle.customColors.playlistDrawerBackgroundColor ??
playerStyle.colors.primaryContainer)
: undefined,
},
]}
Expand Down Expand Up @@ -145,7 +145,7 @@ export default () => {
{
backgroundColor:
currentPlaylist.id ===
playlists[StorageKeys.SEARCH_PLAYLIST_KEY]?.id
playlists[StorageKeys.SEARCH_PLAYLIST_KEY]?.id
? (playerStyle.colors.primaryContainer ??
playerStyle.customColors.playlistDrawerBackgroundColor)
: undefined,
Expand All @@ -161,7 +161,7 @@ export default () => {
}
leadColor={
currentPlayingList.id ===
playlists[StorageKeys.SEARCH_PLAYLIST_KEY].id
playlists[StorageKeys.SEARCH_PLAYLIST_KEY].id
? playerStyle.colors.primary
: undefined
}
Expand Down
8 changes: 8 additions & 0 deletions src/components/setting/DeveloperSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
enableTanaka,
} from '@hooks/useTanakaAmazingCommodities';
import { isAndroid } from '@utils/RNUtils';
import { purchaseVIP } from '@hooks/useVIP';

enum Icons {
setlog = 'console',
Expand All @@ -44,6 +45,7 @@ enum Icons {
fade = 'cosine-wave',
plugins = 'puzzle',
Tanaka = 'emoticon-devil',
VIP = 'cash',
}

enum VIEW {
Expand Down Expand Up @@ -322,6 +324,12 @@ const Home = ({ navigation }: NoxComponent.StackNavigationProps) => {
}
settingCategory="DeveloperSettings"
/>
<SettingListItem
icon={Icons.VIP}
settingName="VIP"
onPress={purchaseVIP}
settingCategory="DeveloperSettings"
/>
</List.Section>
</ScrollView>
<GenericSelectDialog
Expand Down
2 changes: 1 addition & 1 deletion src/enums/Playlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ export enum SortOptions {
PreviousOrder = 'PREVIOUS_ORDER',
}

export const PLAYLIST_MEDIAID = 'playlist-';
export const PlaylistMediaID = 'playlist-';
6 changes: 3 additions & 3 deletions src/hooks/usePlayback.migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import { NoxRepeatMode } from '@enums/RepeatMode';
import noxPlayingList, { setPlayingIndex } from '@stores/playingList';
import { dataSaverPlaylist, dataSaverSongs } from '@utils/Cache';
import { PLAYLIST_MEDIAID, PlaylistTypes } from '@enums/Playlist';
import { PlaylistMediaID, PlaylistTypes } from '@enums/Playlist';
import { fetchCurrentMusicTop } from '@utils/mediafetch/biliMusicTop';

const { getState } = noxPlayingList;
Expand Down Expand Up @@ -102,8 +102,8 @@ export const _playFromMediaId = async ({
playlistIds,
}: PlayFromMediaID) => {
logger.info(`[playFromMediaId]: ${mediaId}`);
if (mediaId.startsWith(PLAYLIST_MEDIAID)) {
mediaId = mediaId.substring(PLAYLIST_MEDIAID.length);
if (mediaId.startsWith(PlaylistMediaID)) {
mediaId = mediaId.substring(PlaylistMediaID.length);
// play a playlist.
if (playlists[mediaId] === undefined) {
logger.warn(`[Playback] ${mediaId} doesnt exist.`);
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/usePlaybackAA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import TrackPlayer from 'react-native-track-player';
import { useTranslation } from 'react-i18next';
import i18n from 'i18next';

import { PLAYLIST_MEDIAID } from '@enums/Playlist';
import { PlaylistMediaID } from '@enums/Playlist';
import usePlayback from './usePlayback';
import { useNoxSetting } from '@stores/useApp';
import { IntentData } from '@enums/Intent';
Expand All @@ -28,7 +28,7 @@ export const buildBrowseTree = (
],
PlaylistTab: Object.keys(playlists).map(key => {
return {
mediaId: `${PLAYLIST_MEDIAID}${key}`,
mediaId: `${PlaylistMediaID}${key}`,
title: playlists[key].title,
playable: '0',
};
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/usePlaybackCarplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from 'react-native-carplay';
import { useTranslation } from 'react-i18next';

import { PLAYLIST_MEDIAID } from '@enums/Playlist';
import { PlaylistMediaID } from '@enums/Playlist';
import usePlayback from './usePlayback';
import { cycleThroughPlaymodeIOS as cyclePlaymode } from '@stores/playingList';
import { isIOS } from '@utils/RNUtils';
Expand Down Expand Up @@ -47,7 +47,7 @@ export default () => {
return pushNowPlayingTemplate();
}
playFromMediaId(
`${PLAYLIST_MEDIAID}${playlistIds[item.index - 1]}`,
`${PlaylistMediaID}${playlistIds[item.index - 1]}`,
).then(() => pushNowPlayingTemplate());
},
});
Expand Down
8 changes: 4 additions & 4 deletions src/hooks/useSetupPlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ const initializePlayer = async (safeMode = false) => {

export const appStartupInit = initializePlayer();

export default ({ intentData }: NoxComponent.AppProps) => {
export default ({ intentData, vip }: NoxComponent.SetupPlayerProps) => {
const [playerReady, setPlayerReady] = useState<boolean>(false);
const { updateVersion, checkVersion } = useVersionCheck();
const setIntentData = useNoxSetting(state => state.setIntentData);
const { checkPlayStoreUpdates } = usePlayStore();

useEffect(() => {
// TODO: if non VIP, call NoxModule?.loadRN() to start loading while displaying
// splash screen; else, stuff loading in the native splashsceren
NoxModule?.loadRN();
if (!vip) {
NoxModule?.loadRN();
}
let unmounted = false;
(async () => {
await appStartupInit;
Expand Down
20 changes: 20 additions & 0 deletions src/hooks/useVIP.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as SecureStore from 'expo-secure-store';
import { useState } from 'react';

const VIPKey = 'APMVIP';

export const purchaseVIP = () => {
SecureStore.setItemAsync(VIPKey, '1');
};

export const loseVIP = () => {
SecureStore.deleteItemAsync(VIPKey);
};

const useVIP = () => {
const [vip, setVip] = useState(SecureStore.getItem(VIPKey) !== null);

return { vip };
};

export default useVIP;
3 changes: 3 additions & 0 deletions src/types/component.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ declare global {
intentBundle: null | any;
rootTag: number;
}
interface SetupPlayerProps extends AppProps {
vip?: boolean;
}
interface NavigationProps {
navigation: DrawerNavigationProp<ParamListBase>;
}
Expand Down
22 changes: 21 additions & 1 deletion src/utils/Bilibili/BiliUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { logger } from '@utils/Logger';
* as "authentication." returns the currently logged in bilibili username.
* @returns dict.
*/
export default async () => {
const getUser = async () => {
try {
const val = await fetch('https://api.bilibili.com/x/web-interface/nav');
const res = await val.json();
Expand All @@ -17,3 +17,23 @@ export default async () => {
return { uname: '' };
}
};

const getUserGuard = async () => {
const uid = (await getUser()).mid;
const res = await fetch(
`https://api.live.bilibili.com/xlive/web-ucenter/user/MedalWall?target_id=${uid}`,
);
const data = await res.json();

return data.data.list;
};

// simple function that filters is user has guard > 0.
export const getHasGuard = async (hasGuard: number[] = []) => {
const guards = await getUserGuard();
return guards.filter(
(guard: any) => guard.guard_level > 0 && hasGuard.includes(guard.target_id),
);
};

export default getUser;

0 comments on commit d8f92e1

Please sign in to comment.