Lg0gs / react-native-corner-video

MIT License
22 stars 1 forks source link

Corner video stuck in the actual frame and looping it #3

Open ElMahdiAboulmanadel opened 3 weeks ago

ElMahdiAboulmanadel commented 3 weeks ago

Firstly, thank you very much for this amazing component!

I installed and followed the usage instructions in a new Bare React Native app 0.75 using community cli. I can see the video (using the same uri in the examples) and also hear the sound perfectly but when I press and hold the video, the corner video gets stuck in the actual frame and repeats it. For information, I'm using React Navigation, navigation container and stack navigator and I put the videowrapper inside a bottom sheet.

            import * as React from 'react';
            import {Button} from '@ui/button';
            import {Text} from '@ui/text';
            import {HelpCircle} from '@lib/icons/Question';
            import {View, Dimensions} from 'react-native';
            import {useColorScheme} from '@lib/useColorScheme';
            import VideoWrapper from 'react-native-corner-video';
            import BottomSheetModal from '@components/ui/bottomDrawer';
            import type Video from 'react-native-video';

            // Constants for video source
            const VIDEO_SOURCE = 'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4';

            function VideoContent({
              screenName,
              isVisible,
              onClose,
            }: {
              screenName: string;
              isVisible: boolean;
              onClose: () => void;
            }) {
              const {isDarkColorScheme} = useColorScheme();
              const windowHeight = Dimensions.get('window').height;
              const videoRef = React.useRef<typeof Video>(null);
              const [currentTime, setCurrentTime] = React.useState(0);

              // Handle video time updates
              const handleProgress = (progress: { currentTime: number }) => {
                setCurrentTime(progress.currentTime);
              };

              // Corner video configuration
              const cornerConfig = {
                videoProps: {
                  source: { uri: VIDEO_SOURCE },
                  resizeMode: 'cover',
                  controls: true,
                  repeat: true,
                  muted: false,
                  volume: 100,
                  playInBackground: true,
                  onProgress: handleProgress,
                  ref: videoRef,
                  controlsStyles: {
                    hideForward: true,
                    hideRewind: true,
                    hideNext: true,
                    hidePrevious: true,
                  },
                },
                cornerProps: {
                  width: 160,  // Smaller size for corner video
                  height: 90,  // 16:9 aspect ratio
                  top: 20,     // Padding from top
                  right: 20,   // Padding from right
                  bottom: 0,
                  left: 0,
                },
              };

              return (
                <BottomSheetModal
                  isVisible={isVisible}
                  onClose={onClose}
                  headerText={`Tutorial: How to use ${screenName}?`}
                  height={windowHeight * 0.85}
                  backdropOpacity={0.7}
                  containerStyle={{
                    backgroundColor: isDarkColorScheme ? '#1F1F1F' : '#fff',
                    shadowColor: 'black',
                    shadowOpacity: 0.2,
                    borderTopLeftRadius: 20,
                    borderTopRightRadius: 20,
                  }}>
                  <View className="p-4">
                    <View
                      style={{
                        marginTop: 15,
                        height: 500,
                        width: '100%',
                        backgroundColor: 'black',
                        borderRadius: 20,
                        overflow: 'hidden',
                      }}>
                      <VideoWrapper
                        {...cornerConfig}
                        style={{
                          height: 500,
                          borderRadius: 20,
                          width: '100%',
                        }}
                      />
                    </View>
                    <View className="mt-4">
                      <Text className="text-center text-sm text-gray-500">
                        Press and hold the video to minimize it while using the app
                      </Text>
                    </View>
                  </View>
                </BottomSheetModal>
              );
            }

            const TutorialVideo = ({screenName}: {screenName: string}) => {
              const [isVisible, setIsVisible] = React.useState(false);

              return (
                <>
                  <Button
                    onPress={() => setIsVisible(true)}
                    className="bg-transparent h-fit w-4">
                    <HelpCircle
                      strokeWidth={1.6}
                      className="text-black dark:text-white"
                    />
                  </Button>
                  <VideoContent
                    screenName={screenName}
                    isVisible={isVisible}
                    onClose={() => setIsVisible(false)}
                  />
                </>
              );
            };

            export default TutorialVideo;
ElMahdiAboulmanadel commented 3 weeks ago

Here is the fix that worked perfectly for me:

ElMahdiAboulmanadel commented 3 weeks ago

I used Patch-package to create the following patch, feel free to use it. react-native-corner-video+1.0.2.patch