Skip to content

Commit

Permalink
Add review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Skalakid committed Mar 22, 2024
1 parent 328fbd8 commit e75f1c4
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
12 changes: 6 additions & 6 deletions src/components/Attachments/AttachmentCarousel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function AttachmentCarousel({report, reportActions, parentReportActions, source,
const theme = useTheme();
const styles = useThemeStyles();
const scrollRef = useRef(null);
const {isFullscreenRef} = useFullScreenContext();
const {isFullScreenRef} = useFullScreenContext();

const canUseTouchScreen = DeviceCapabilities.canUseTouchScreen();

Expand Down Expand Up @@ -79,7 +79,7 @@ function AttachmentCarousel({report, reportActions, parentReportActions, source,
*/
const updatePage = useCallback(
({viewableItems}) => {
if (isFullscreenRef.current) {
if (isFullScreenRef.current) {
return;
}

Expand All @@ -98,7 +98,7 @@ function AttachmentCarousel({report, reportActions, parentReportActions, source,

onNavigate(entry.item);
},
[isFullscreenRef, onNavigate],
[isFullScreenRef, onNavigate],
);

/**
Expand All @@ -107,7 +107,7 @@ function AttachmentCarousel({report, reportActions, parentReportActions, source,
*/
const cycleThroughAttachments = useCallback(
(deltaSlide) => {
if (isFullscreenRef.current) {
if (isFullScreenRef.current) {
return;
}
const nextIndex = page + deltaSlide;
Expand All @@ -119,7 +119,7 @@ function AttachmentCarousel({report, reportActions, parentReportActions, source,

scrollRef.current.scrollToIndex({index: nextIndex, animated: canUseTouchScreen});
},
[attachments, canUseTouchScreen, isFullscreenRef, page],
[attachments, canUseTouchScreen, isFullScreenRef, page],
);

/**
Expand Down Expand Up @@ -167,7 +167,7 @@ function AttachmentCarousel({report, reportActions, parentReportActions, source,
<View
style={[styles.flex1, styles.attachmentCarouselContainer]}
onLayout={({nativeEvent}) => {
if (isFullscreenRef.current) {
if (isFullScreenRef.current) {
return;
}
setContainerWidth(PixelRatio.roundToNearestPixel(nativeEvent.layout.width));
Expand Down
14 changes: 7 additions & 7 deletions src/components/VideoPlayer/BaseVideoPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function BaseVideoPlayer({
updateCurrentlyPlayingURL,
videoResumeTryNumber,
} = usePlaybackContext();
const {isFullscreenRef} = useFullScreenContext();
const {isFullScreenRef} = useFullScreenContext();
const [duration, setDuration] = useState(videoDuration * 1000);
const [position, setPosition] = useState(0);
const [isPlaying, setIsPlaying] = useState(false);
Expand Down Expand Up @@ -134,7 +134,7 @@ function BaseVideoPlayer({
// fix for iOS native and mWeb: when switching to fullscreen and then exiting
// the fullscreen mode while playing, the video pauses
if (e.fullscreenUpdate === VideoFullscreenUpdate.PLAYER_DID_DISMISS) {
isFullscreenRef.current = false;
isFullScreenRef.current = false;
// we need to use video state ref to check if video is playing, to catch proper state after exiting fullscreen
// and also fix a bug with fullscreen mode dismissing when handleFullscreenUpdate function changes
if (videoStateRef.current && videoStateRef.current.isPlaying) {
Expand All @@ -144,7 +144,7 @@ function BaseVideoPlayer({
}
}
},
[isFullscreenRef, onFullscreenUpdate, pauseVideo, playVideo, videoResumeTryNumber],
[isFullScreenRef, onFullscreenUpdate, pauseVideo, playVideo, videoResumeTryNumber],
);

const bindFunctions = useCallback(() => {
Expand All @@ -168,15 +168,15 @@ function BaseVideoPlayer({

// update shared video elements
useEffect(() => {
if (shouldUseSharedVideoElement || url !== currentlyPlayingURL || isFullscreenRef.current) {
if (shouldUseSharedVideoElement || url !== currentlyPlayingURL || isFullScreenRef.current) {
return;
}
shareVideoPlayerElements(videoPlayerRef.current, videoPlayerElementParentRef.current, videoPlayerElementRef.current, isUploading);
}, [currentlyPlayingURL, shouldUseSharedVideoElement, shareVideoPlayerElements, updateSharedElements, url, isUploading, isFullscreenRef]);
}, [currentlyPlayingURL, shouldUseSharedVideoElement, shareVideoPlayerElements, updateSharedElements, url, isUploading, isFullScreenRef]);

// append shared video element to new parent (used for example in attachment modal)
useEffect(() => {
if (url !== currentlyPlayingURL || !sharedElement || isFullscreenRef.current) {
if (url !== currentlyPlayingURL || !sharedElement || isFullScreenRef.current) {
return;
}

Expand All @@ -201,7 +201,7 @@ function BaseVideoPlayer({
newParentRef.childNodes[0].remove();
originalParent.appendChild(sharedElement);
};
}, [bindFunctions, currentVideoPlayerRef, currentlyPlayingURL, isFullscreenRef, originalParent, sharedElement, shouldUseSharedVideoElement, url]);
}, [bindFunctions, currentVideoPlayerRef, currentlyPlayingURL, isFullScreenRef, originalParent, sharedElement, shouldUseSharedVideoElement, url]);

return (
<>
Expand Down
6 changes: 3 additions & 3 deletions src/components/VideoPlayer/VideoPlayerControls/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function VideoPlayerControls({duration, position, url, videoPlayerRef, isPlaying
const styles = useThemeStyles();
const {translate} = useLocalize();
const {updateCurrentlyPlayingURL} = usePlaybackContext();
const {isFullscreenRef} = useFullScreenContext();
const {isFullScreenRef} = useFullScreenContext();
const [shouldShowTime, setShouldShowTime] = useState(false);
const iconSpacing = small ? styles.mr3 : styles.mr4;

Expand All @@ -58,10 +58,10 @@ function VideoPlayerControls({duration, position, url, videoPlayerRef, isPlaying
};

const enterFullScreenMode = useCallback(() => {
isFullscreenRef.current = true;
isFullScreenRef.current = true;
updateCurrentlyPlayingURL(url);
videoPlayerRef.current.presentFullscreenPlayer();
}, [isFullscreenRef, updateCurrentlyPlayingURL, url, videoPlayerRef]);
}, [isFullScreenRef, updateCurrentlyPlayingURL, url, videoPlayerRef]);

const seekPosition = useCallback(
(newPosition: number) => {
Expand Down
6 changes: 3 additions & 3 deletions src/components/VideoPlayerContexts/FullScreenContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {FullScreenContext} from './types';
const Context = React.createContext<FullScreenContext | null>(null);

function FullScreenContextProvider({children}: ChildrenProps) {
const isFullscreenRef = useRef(false);
const isFullScreenRef = useRef(false);
const lockedWindowDimensionsRef = useRef<WindowDimensions | null>(null);

const lockWindowDimensions = useCallback((newWindowDimensions: WindowDimensions) => {
Expand All @@ -17,14 +17,14 @@ function FullScreenContextProvider({children}: ChildrenProps) {
lockedWindowDimensionsRef.current = null;
}, []);

const contextValue = useMemo(() => ({isFullscreenRef, lockedWindowDimensionsRef, lockWindowDimensions, unlockWindowDimensions}), [lockWindowDimensions, unlockWindowDimensions]);
const contextValue = useMemo(() => ({isFullScreenRef, lockedWindowDimensionsRef, lockWindowDimensions, unlockWindowDimensions}), [lockWindowDimensions, unlockWindowDimensions]);
return <Context.Provider value={contextValue}>{children}</Context.Provider>;
}

function useFullScreenContext() {
const fullscreenContext = useContext(Context);
if (!fullscreenContext) {
throw new Error('usePlaybackContext must be used within a PlaybackContextProvider');
throw new Error('useFullScreenContext must be used within a FullScreenContextProvider');
}
return fullscreenContext;
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/VideoPlayerContexts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type VideoPopoverMenuContext = {
};

type FullScreenContext = {
isFullscreenRef: MutableRefObject<boolean>;
isFullScreenRef: MutableRefObject<boolean>;
lockedWindowDimensionsRef: MutableRefObject<WindowDimensions | null>;
lockWindowDimensions: (newWindowDimensions: WindowDimensions) => void;
unlockWindowDimensions: () => void;
Expand Down
8 changes: 4 additions & 4 deletions src/hooks/useWindowDimensions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const isMobile = Browser.isMobile();
* A convenience wrapper around React Native's useWindowDimensions hook that also provides booleans for our breakpoints.
*/
export default function (useCachedViewportHeight = false): WindowDimensions {
const {isFullscreenRef, lockedWindowDimensionsRef, lockWindowDimensions, unlockWindowDimensions} = useContext(FullScreenContext) ?? {
isFullscreenRef: useRef(false),
const {isFullScreenRef, lockedWindowDimensionsRef, lockWindowDimensions, unlockWindowDimensions} = useContext(FullScreenContext) ?? {
isFullScreenRef: useRef(false),
lockedWindowDimensionsRef: useRef<WindowDimensions | null>(null),
lockWindowDimensions: () => {},
unlockWindowDimensions: () => {},
Expand Down Expand Up @@ -102,7 +102,7 @@ export default function (useCachedViewportHeight = false): WindowDimensions {
isSmallScreen,
};

if (!lockedWindowDimensionsRef.current && !isFullscreenRef.current) {
if (!lockedWindowDimensionsRef.current && !isFullScreenRef.current) {
return windowDimensions;
}

Expand All @@ -125,7 +125,7 @@ export default function (useCachedViewportHeight = false): WindowDimensions {
const didScreenReturnToOriginalSize = lockedWindowDimensionsRef.current.windowWidth === windowWidth && lockedWindowDimensionsRef.current.windowHeight === windowHeight;

// if video exits fullscreen mode, unlock the window dimensions
if (lockedWindowDimensionsRef.current && !isFullscreenRef.current && didScreenReturnToOriginalSize) {
if (lockedWindowDimensionsRef.current && !isFullScreenRef.current && didScreenReturnToOriginalSize) {
const lastLockedWindowDimensions = {...lockedWindowDimensionsRef.current};
unlockWindowDimensions();
return lastLockedWindowDimensions;
Expand Down

0 comments on commit e75f1c4

Please sign in to comment.