Skip to content

Commit 4fddffb

Browse files
author
Petr Konecny
committed
fix: android issues
1 parent 5355a7f commit 4fddffb

File tree

3 files changed

+45
-31
lines changed

3 files changed

+45
-31
lines changed

example/examples/EnteringAnimationExample.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ const Slide = ({ image, title, index }: { image: string; title: string; index: n
3333

3434
return (
3535
<View key={index} style={styles.slide}>
36-
<Image key={image} source={{ uri: image }} style={styles.image} contentFit="cover" />
36+
<Image source={{ uri: image }} style={styles.image} contentFit="cover" />
3737
<LinearGradient colors={['transparent', 'rgba(0,0,0,0.8)']} style={styles.gradient}>
38-
<SlideAnimatedView {...animationConfig}>
38+
<SlideAnimatedView style={styles.textContainer} {...animationConfig}>
3939
<Text style={styles.title}>{title}</Text>
4040
<Text style={styles.subtitle}>
4141
Animation: {animationNames[index % animationNames.length]}
@@ -68,6 +68,9 @@ export default function EnteringAnimationExample() {
6868
}
6969

7070
const styles = StyleSheet.create({
71+
textContainer: {
72+
flex: 1,
73+
},
7174
container: {
7275
flex: 1,
7376
backgroundColor: '#fff',

example/examples/VideoCarouselExample.tsx

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,30 @@ import {
33
CarouselContextProvider,
44
useAutoCarouselSlideIndex,
55
} from '@strv/react-native-hero-carousel'
6-
import { SafeAreaView, StyleSheet, View, Text, Pressable } from 'react-native'
6+
import { SafeAreaView, StyleSheet, View, Text, Pressable, Dimensions, Platform } from 'react-native'
77
import { useVideoPlayer, VideoView } from 'expo-video'
88
import { LinearGradient } from 'expo-linear-gradient'
99
import { useActiveSlideEffect, useIsActiveSlide } from '@/hooks/useActiveSlideEffect'
1010
import { useEffect, useRef, useState } from 'react'
1111
import { TimerPagination } from './components/TimerPagination'
1212
import { useEvent, useEventListener } from 'expo'
1313

14+
const { width, height } = Dimensions.get('window')
1415
// Sample video URLs - these are publicly available videos that work well for testing
1516
const videos = [
16-
'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4',
17-
'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4',
1817
'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerBlazes.mp4',
1918
'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerEscapes.mp4',
2019
'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerFun.mp4',
20+
'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4',
21+
'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4',
2122
]
2223

2324
const videoTitles = [
24-
'Big Buck Bunny',
25-
'Elephants Dream',
2625
'For Bigger Blazes',
2726
'For Bigger Escapes',
2827
'For Bigger Fun',
28+
'Big Buck Bunny',
29+
'Elephants Dream',
2930
]
3031

3132
const Slide = ({ videoUri, title, index }: { videoUri: string; title: string; index: number }) => {
@@ -58,26 +59,33 @@ const Slide = ({ videoUri, title, index }: { videoUri: string; title: string; in
5859
}, [isActiveSlide, duration, runAutoScroll])
5960

6061
return (
61-
<Pressable
62-
key={index}
63-
style={styles.slide}
64-
onPress={() => {
65-
if (isPlaying) {
66-
player.pause()
67-
intervalRef.current?.pause()
68-
} else {
69-
player.play()
70-
intervalRef.current?.resume()
71-
}
72-
}}
73-
>
74-
<VideoView player={player} style={styles.video} contentFit="cover" nativeControls={false} />
75-
<LinearGradient colors={['rgba(0,0,0,0.8)', 'transparent']} style={styles.topGradient} />
76-
<LinearGradient colors={['transparent', 'rgba(0,0,0,0.8)']} style={styles.gradient}>
77-
<Text style={styles.title}>{title}</Text>
78-
<Text style={styles.subtitle}>Swipe to navigate • Tap to play/pause</Text>
79-
</LinearGradient>
80-
</Pressable>
62+
<View style={styles.slide}>
63+
<Pressable
64+
key={index}
65+
style={styles.slide}
66+
onPress={() => {
67+
if (isPlaying) {
68+
player.pause()
69+
intervalRef.current?.pause()
70+
} else {
71+
player.play()
72+
intervalRef.current?.resume()
73+
}
74+
}}
75+
>
76+
<VideoView
77+
player={player}
78+
style={styles.video}
79+
contentFit={Platform.OS === 'android' ? 'fill' : 'cover'}
80+
nativeControls={false}
81+
/>
82+
<LinearGradient colors={['rgba(0,0,0,0.8)', 'transparent']} style={styles.topGradient} />
83+
<LinearGradient colors={['transparent', 'rgba(0,0,0,0.8)']} style={styles.gradient}>
84+
<Text style={styles.title}>{title}</Text>
85+
<Text style={styles.subtitle}>Swipe to navigate • Tap to play/pause</Text>
86+
</LinearGradient>
87+
</Pressable>
88+
</View>
8189
)
8290
}
8391

@@ -110,8 +118,8 @@ const styles = StyleSheet.create({
110118
overflow: 'hidden',
111119
},
112120
video: {
113-
width: '100%',
114-
height: '100%',
121+
width: width,
122+
height: height,
115123
},
116124
gradient: {
117125
position: 'absolute',

src/components/SlideAnimatedView/index.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type SlideAnimatedViewProps = {
1616
layout?: AnimatedProps<ViewProps>['layout']
1717
enteringThreshold?: number
1818
exitingThreshold?: number
19+
style?: AnimatedProps<ViewProps>['style']
1920
}
2021

2122
export const SlideAnimatedView = ({
@@ -25,6 +26,7 @@ export const SlideAnimatedView = ({
2526
layout,
2627
enteringThreshold = 0.99,
2728
exitingThreshold = 0.01,
29+
style,
2830
}: SlideAnimatedViewProps) => {
2931
const { index, total } = useAutoCarouselSlideIndex()
3032
const { scrollValue } = useCarouselContext()
@@ -36,7 +38,7 @@ export const SlideAnimatedView = ({
3638
thisValue: 1,
3739
valueAfter: 0,
3840
})
39-
})
41+
}, [index, total, scrollValue])
4042

4143
// Track when value becomes 1 to trigger entering animation
4244
useAnimatedReaction(
@@ -57,14 +59,15 @@ export const SlideAnimatedView = ({
5759
runOnJS(setShouldShow)(false)
5860
}
5961
},
62+
[enteringThreshold, exitingThreshold],
6063
)
6164

6265
if (!shouldShow) {
6366
return null
6467
}
6568

6669
return (
67-
<Animated.View entering={entering} exiting={exiting} layout={layout}>
70+
<Animated.View entering={entering} exiting={exiting} layout={layout} style={style}>
6871
{children}
6972
</Animated.View>
7073
)

0 commit comments

Comments
 (0)