Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: motionlayout perf #642

Merged
merged 3 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/app/src/main/res/xml/shortcuts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<shortcut
android:shortcutId="play_all"
android:enabled="true"
android:icon="@drawable/media3_icon_shuffle_on"
android:icon="@drawable/media3_icon_circular_play"
android:shortcutShortLabel="@string/play_all"
android:shortcutLongLabel="@string/play_all">
<intent
Expand Down
76 changes: 41 additions & 35 deletions src/components/miniplayer/Artwork.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import Animated, {
useAnimatedStyle,
useDerivedValue,
} from 'react-native-reanimated';
import { Image } from 'expo-image';
import { useEffect, useState } from 'react';

import { styles } from '../style';
Expand All @@ -28,23 +27,31 @@ export default ({ miniplayerHeight, opacity, onPress, expand }: Props) => {
const artworkWidth = useDerivedValue(() => {
return Math.min(miniplayerHeight.value - 25, width);
});
const artworkBottom = useDerivedValue(() => {
const val = miniplayerHeight.value - MinPlayerHeight - 5;
const overflowBottom = Math.max(0, miniplayerHeight.value - 100 - width);
return Math.min(val - overflowBottom);
const artworkScale = useDerivedValue(() => {
return artworkWidth.value / width;
});
const artworkLeft = useDerivedValue(() => {
const val = 5 + MinPlayerHeight - miniplayerHeight.value;
if (val < 0) return 0;
return val;
const expandDiff = useDerivedValue(
() => miniplayerHeight.value - MinPlayerHeight,
);

const artworkTranslateY = useDerivedValue(() => {
return Math.min(100, 165 + MinPlayerHeight - width + expandDiff.value / 2);
});
const artworkTranslateX = useDerivedValue(() => {
if (expandDiff.value < 6) {
return 5 - expandDiff.value + (artworkWidth.value - width) / 2;
}
return (artworkWidth.value - width) / 2;
});

const animatedStyle = useAnimatedStyle(() => {
return {
width: artworkWidth.value,
height: artworkWidth.value,
bottom: -artworkBottom.value,
left: artworkLeft.value,
transform: [
{ translateX: artworkTranslateX.value },
{ translateY: artworkTranslateY.value },
{ scaleX: artworkScale.value },
{ scaleY: artworkScale.value },
],
opacity: opacity.value,
zIndex: opacity.value > 0 ? 1 : -1,
};
Expand All @@ -54,7 +61,7 @@ export default ({ miniplayerHeight, opacity, onPress, expand }: Props) => {
if (miniplayerHeight.value === MinPlayerHeight) {
return expand();
}
if (artworkWidth.value === width) {
if (artworkScale.value === 1) {
return onPress();
}
};
Expand All @@ -64,26 +71,25 @@ export default ({ miniplayerHeight, opacity, onPress, expand }: Props) => {
}, [track]);

return (
<Animated.View
style={[
{
position: 'absolute',
},
animatedStyle,
]}
>
<TouchableWithoutFeedback onPress={onImagePress}>
<Image
style={styles.flex}
source={
hideCoverInMobile
? 0
: {
uri: `${overwriteAlbumArt ?? track?.artwork}`,
}
}
/>
</TouchableWithoutFeedback>
</Animated.View>
<TouchableWithoutFeedback onPress={onImagePress}>
<Animated.Image
style={[
styles.flex,
{
width,
height: width,
position: 'absolute',
},
animatedStyle,
]}
source={
hideCoverInMobile
? undefined
: {
uri: `${overwriteAlbumArt ?? track?.artwork}`,
}
}
/>
</TouchableWithoutFeedback>
);
};