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

(WIP) fix: removed statusbar code and fixed lagging while scale value changes #2715

Merged
merged 4 commits into from
Jan 16, 2025
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useState } from 'react';
import { Image, Pressable } from 'react-native';
import { StatusBar } from 'expo-status-bar';
import {
ImageViewer,
ImageViewerBackdrop,
Expand All @@ -20,6 +21,7 @@ const ImageViewerBasic = ({ ...props }: any) => {
const [visible, setVisible] = useState(false);
return (
<>
<StatusBar hidden={visible} />
<Pressable onPress={() => setVisible(true)}>
<Image
source={{ uri: Images[0].url }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
} from 'react-native';
import { transformedCode } from '../../utils';
import { useState } from 'react';
import { StatusBar } from 'expo-status-bar';

import {
CodePreview,
Expand Down Expand Up @@ -60,6 +61,7 @@ This is an illustration of **ImageViewer** component.
const Images = [{ id: 1, url: 'https://img.freepik.com/free-photo/young-boy-learning-how-ride-horse_23-2150460636.jpg' }];
return (
<Center>
<StatusBar hidden={visible}/>
<Pressable onPress={() => setVisible(true)}>
<Image
source={{ uri: Images[0].url }}
Expand Down Expand Up @@ -102,6 +104,7 @@ This is an illustration of **ImageViewer** component.
Pressable,
Image,
Center,
StatusBar,
},
argsType: {},
}}
Expand Down Expand Up @@ -360,6 +363,7 @@ import { CloseIcon, Icon } from '@/components/ui/icon';
import React, { useState } from 'react';
import { Pressable, Image } from 'react-native';
import { Center } from '@/components/ui/center';
import { StatusBar } from 'expo-status-bar';
```

<Wrapper>
Expand All @@ -377,6 +381,7 @@ import { Center } from '@/components/ui/center';
const Images = [{ id: 1, url: 'https://img.freepik.com/free-photo/young-boy-learning-how-ride-horse_23-2150460636.jpg' }];
return (
<Center>
<StatusBar hidden={visible}/>
<Pressable onPress={() => setVisible(true)}>
<Image
source={{ uri: Images[0].url }}
Expand Down Expand Up @@ -419,6 +424,7 @@ import { Center } from '@/components/ui/center';
Pressable,
Image,
Center,
StatusBar,
},
argsType: {},
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,5 +234,5 @@
"hooks": ["useBreakpointValue"]
}
},
"IgnoredComponents": ["bottomsheet", "image-viewer"]
"IgnoredComponents": ["bottomsheet", "image-viewer", "pin-input"]
}
18 changes: 6 additions & 12 deletions packages/unstyled/image-viewer/src/ImageViewerContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
withSpring,
withTiming,
} from 'react-native-reanimated';
import { Dimensions, StatusBar } from 'react-native';
import { Dimensions } from 'react-native';
import type { InterfaceImageViewerContentProps } from './types';

const { width: SCREEN_WIDTH, height: SCREEN_HEIGHT } = Dimensions.get('window');
Expand Down Expand Up @@ -100,13 +100,10 @@ const ImageViewerContent = (
translateY.value = lastTranslateY.value + event.translationY;
} else {
// Normal swipe behavior when not zoomed
if (Math.abs(event.translationY) > Math.abs(event.translationX)) {
translateY.value = event.translationY;
scale.value = Math.max(
0.5,
1 - Math.abs(event.translationY) / SCREEN_HEIGHT
);
}
translateY.value = event.translationY;
scale.value = withSpring(
Math.max(0.5, 1 - Math.abs(event.translationY) / SCREEN_HEIGHT)
);
}
})
.onEnd((event: any) => {
Expand All @@ -120,7 +117,7 @@ const ImageViewerContent = (
if (scale.value <= 1) {
translateX.value = 0;
translateY.value = withSpring(0);
scale.value = withSpring(1);
scale.value = withTiming(1);
savedScale.value = 1;
} else {
// When zoomed, bound the pan values
Expand Down Expand Up @@ -152,8 +149,6 @@ const ImageViewerContent = (
// @ts-ignore
const animatedStyle = useAnimatedStyle(() => {
runOnJS(setScale)(scale.value);
if (scale.value <= 1) {
}
return {
transform: [
{ translateX: translateX.value },
Expand All @@ -165,7 +160,6 @@ const ImageViewerContent = (

return (
<StyledGestureHandlerRootView ref={ref}>
<StatusBar hidden={true} />
{children}
<StyledGestureDetector gesture={composedGesture}>
<StyledAnimated style={animatedStyle}>
Expand Down
Loading