Fix bottom scrubber on android

This commit is contained in:
Zoe Roux 2024-01-28 18:39:16 +01:00
parent 085d337fb7
commit 0cc6274894
4 changed files with 63 additions and 51 deletions

View File

@ -27,7 +27,7 @@ import { ContrastArea } from "../themes";
import { percent } from "yoshiki/native";
import { imageBorderRadius } from "../constants";
export { FastImage } from "./fast-image";
export { Sprite } from "./sprite";
export { BlurhashContainer } from "./blurhash";
export { type Props as ImageProps, Image };

View File

@ -18,10 +18,9 @@
* along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
*/
import { View } from "react-native";
import FImage from "react-native-fast-image";
import { Image, View } from "react-native";
export const FastImage = ({
export const Sprite = ({
src,
alt,
width,
@ -45,21 +44,12 @@ export const FastImage = ({
}) => {
return (
<View style={{ width, height, overflow: "hidden", flexGrow: 0, flexShrink: 0 }}>
<FImage
source={{
uri: src,
priority: FImage.priority.low,
}}
accessibilityLabel={alt}
resizeMode={FImage.resizeMode.cover}
style={[
{
width: width * columns,
height: height * rows,
transform: `translate(${-x}px, ${-y}px)`,
},
style,
]}
<Image
source={{ uri: src }}
alt={alt}
width={width * columns}
height={height * rows}
style={{ transform: [{ translateX: -x }, { translateY: -y }] }}
{...props}
/>
</View>

View File

@ -20,7 +20,7 @@
import NextImage from "next/image";
export const FastImage = ({
export const Sprite = ({
src,
alt,
style,
@ -31,8 +31,8 @@ export const FastImage = ({
src: string;
alt: string;
style?: object;
width: number | string;
height: number | string;
width: number;
height: number;
x: number;
y: number;
}) => {
@ -43,7 +43,13 @@ export const FastImage = ({
alt={alt!}
// Don't use next's server to reprocess images, they are already optimized by kyoo.
unoptimized={true}
style={{ objectFit: "none", objectPosition: `${-x}px ${-y}px`, ...style }}
style={{
objectFit: "none",
objectPosition: `${-x}px ${-y}px`,
flexGrow: 0,
flexShrink: 0,
...style,
}}
{...props}
/>
);

View File

@ -19,11 +19,11 @@
*/
import { useFetch, QueryIdentifier, imageFn, Chapter } from "@kyoo/models";
import { FastImage, P, imageBorderRadius, ts } from "@kyoo/primitives";
import { View } from "react-native";
import { percent, useYoshiki, px, Theme } from "yoshiki/native";
import { Sprite, P, imageBorderRadius, ts } from "@kyoo/primitives";
import { View, Platform } from "react-native";
import { percent, useYoshiki, px, Theme, useForceRerender } from "yoshiki/native";
import { ErrorView } from "../../fetch";
import { useMemo } from "react";
import { useMemo, useState } from "react";
import { useAtomValue } from "jotai";
import { durationAtom, progressAtom } from "../state";
import { toTimerString } from "./left-buttons";
@ -128,7 +128,7 @@ export const ScrubberTooltip = ({
})}
>
{current && (
<FastImage
<Sprite
src={current.url}
alt={""}
width={current.width}
@ -145,10 +145,12 @@ export const ScrubberTooltip = ({
</View>
);
};
let scrubberWidth = 0;
export const BottomScrubber = ({ url }: { url: string }) => {
const { css } = useYoshiki();
const { info, error, stats } = useScrubber(url);
const rerender = useForceRerender();
const progress = useAtomValue(progressAtom);
const duration = useAtomValue(durationAtom) ?? 1;
@ -159,30 +161,44 @@ export const BottomScrubber = ({ url }: { url: string }) => {
return (
<View {...css({ overflow: "hidden" })}>
<View
{...css(
{ flexDirection: "row" },
{
style: {
transform: `translateX(calc(${
(progress / duration) * -width * info.length - width / 2
}px + 50%))`,
},
},
)}
{...(Platform.OS === "web"
? css({ transform: `translateX(50%)` })
: {
// react-native does not support translateX by percentage so we simulate it
style: { transform: [{ translateX: scrubberWidth / 2 }] },
onLayout: (e) => {
if (!e.nativeEvent.layout.width) return;
scrubberWidth = e.nativeEvent.layout.width;
rerender();
},
})}
>
{info.map((thumb) => (
<FastImage
key={thumb.to}
src={thumb.url}
alt=""
width={thumb.width}
height={thumb.height}
x={thumb.x}
y={thumb.y}
columns={stats!.columns}
rows={stats!.rows}
/>
))}
<View
{...css(
{ flexDirection: "row" },
{
style: {
transform: `translateX(${
(progress / duration) * -width * info.length - width / 2
}px)`,
},
},
)}
>
{info.map((thumb) => (
<Sprite
key={thumb.to}
src={thumb.url}
alt=""
width={thumb.width}
height={thumb.height}
x={thumb.x}
y={thumb.y}
columns={stats!.columns}
rows={stats!.rows}
/>
))}
</View>
</View>
<View
{...css({