11import React from 'react' ;
2- import { View , TouchableOpacity , Text , PanResponder , ActivityIndicator , Animated , StyleSheet , Easing } from 'react-native' ;
2+ import { View , TouchableOpacity , Text , PanResponder , ActivityIndicator , Animated , StyleSheet , Easing , Dimensions } from 'react-native' ;
33import { AVPlaybackStatusSuccess } from 'expo-av' ;
44import { Ionicons } from '@expo/vector-icons' ;
55import AdvancedVideo from '../../../AdvancedVideo' ;
66import { CLDVideoLayerProps , ButtonPosition } from './types' ;
77import { formatTime , handleDefaultShare } from './utils' ;
8- import { styles } from './styles' ;
8+ import { styles , getResponsiveStyles } from './styles' ;
99import { TopControls , CenterControls , BottomControls } from './components' ;
1010import { ICON_SIZES } from './constants' ;
1111
@@ -16,6 +16,7 @@ interface CLDVideoLayerState {
1616 seekingPosition : number ;
1717 lastSeekPosition : number ;
1818 isSeekingComplete : boolean ;
19+ isLandscape : boolean ;
1920}
2021
2122export class CLDVideoLayer extends React . Component < CLDVideoLayerProps , CLDVideoLayerState > {
@@ -24,20 +25,28 @@ export class CLDVideoLayer extends React.Component<CLDVideoLayerProps, CLDVideoL
2425 private fadeAnim : Animated . Value ;
2526 private autoHideTimeoutId : NodeJS . Timeout | null = null ;
2627 private panResponder : any ;
28+ private orientationSubscription : any = null ;
29+ private orientationCheckInterval : NodeJS . Timeout | null = null ;
2730
2831 constructor ( props : CLDVideoLayerProps ) {
2932 super ( props ) ;
3033 this . videoRef = React . createRef < AdvancedVideo > ( ) ;
3134 this . seekbarRef = React . createRef < View > ( ) ;
3235 this . fadeAnim = new Animated . Value ( 1 ) ;
3336
37+ // Get initial orientation
38+ const { width, height } = Dimensions . get ( 'window' ) ;
39+ const initialIsLandscape = width > height ;
40+ console . log ( '🏗️ Initial orientation setup:' , { width, height, initialIsLandscape } ) ;
41+
3442 this . state = {
3543 status : null ,
3644 isControlsVisible : true ,
3745 isSeeking : false ,
3846 seekingPosition : 0 ,
3947 lastSeekPosition : 0 ,
4048 isSeekingComplete : false ,
49+ isLandscape : initialIsLandscape ,
4150 } ;
4251
4352 this . panResponder = PanResponder . create ( {
@@ -114,12 +123,56 @@ export class CLDVideoLayer extends React.Component<CLDVideoLayerProps, CLDVideoL
114123 if ( this . state . isControlsVisible ) {
115124 this . startAutoHideTimer ( ) ;
116125 }
126+
127+ // Listen for orientation changes
128+ console . log ( '🚀 Setting up orientation listener. Initial state:' , this . state . isLandscape ) ;
129+
130+ // Try multiple approaches for orientation detection
131+ this . orientationSubscription = Dimensions . addEventListener ( 'change' , this . handleOrientationChange ) ;
132+
133+ // Also check orientation periodically as fallback
134+ this . orientationCheckInterval = setInterval ( ( ) => {
135+ const { width, height } = Dimensions . get ( 'window' ) ;
136+ const isLandscape = width > height ;
137+ if ( isLandscape !== this . state . isLandscape ) {
138+ console . log ( '🔄 Orientation detected via polling:' , { width, height, isLandscape } ) ;
139+ this . setState ( { isLandscape } ) ;
140+ }
141+ } , 500 ) ;
142+
143+ console . log ( '✅ Orientation listener registered' ) ;
117144 }
118145
119146 componentWillUnmount ( ) {
120147 this . clearAutoHideTimer ( ) ;
148+
149+ // Remove orientation listener
150+ if ( this . orientationSubscription && this . orientationSubscription . remove ) {
151+ this . orientationSubscription . remove ( ) ;
152+ }
153+
154+ // Clear orientation polling interval
155+ if ( this . orientationCheckInterval ) {
156+ clearInterval ( this . orientationCheckInterval ) ;
157+ this . orientationCheckInterval = null ;
158+ }
121159 }
122160
161+ handleOrientationChange = ( { window } : any ) => {
162+ const { width, height } = window ;
163+ const isLandscape = width > height ;
164+ console . log ( '🔄 Orientation change detected:' , {
165+ width,
166+ height,
167+ isLandscape,
168+ currentState : this . state . isLandscape
169+ } ) ;
170+ if ( isLandscape !== this . state . isLandscape ) {
171+ console . log ( '📱 Updating orientation state to:' , isLandscape ) ;
172+ this . setState ( { isLandscape } ) ;
173+ }
174+ } ;
175+
123176 clearAutoHideTimer = ( ) => {
124177 if ( this . autoHideTimeoutId ) {
125178 clearTimeout ( this . autoHideTimeoutId ) ;
@@ -247,11 +300,17 @@ export class CLDVideoLayer extends React.Component<CLDVideoLayerProps, CLDVideoL
247300
248301 render ( ) {
249302 const { cldVideo, videoUrl, onBack, backButtonPosition, shareButtonPosition, showCenterPlayButton = true } = this . props ;
250- const { status } = this . state ;
303+ const { status, isLandscape } = this . state ;
251304 const progress = this . getProgress ( ) ;
252305 const currentPosition = this . getCurrentPosition ( ) ;
253306 const isVideoLoaded = status ?. isLoaded === true ;
254307
308+ // Get responsive styles based on current orientation
309+ const responsiveStyles = getResponsiveStyles ( isLandscape ) ;
310+
311+ // Debug log for render
312+ console . log ( '🎨 Rendering with isLandscape:' , isLandscape ) ;
313+
255314 return (
256315 < TouchableOpacity
257316 activeOpacity = { 1 }
@@ -283,6 +342,7 @@ export class CLDVideoLayer extends React.Component<CLDVideoLayerProps, CLDVideoL
283342 onShare = { this . handleShare }
284343 backButtonPosition = { backButtonPosition }
285344 shareButtonPosition = { shareButtonPosition }
345+ isLandscape = { isLandscape }
286346 />
287347 { showCenterPlayButton && (
288348 < CenterControls status = { status } onPlayPause = { this . handlePlayPause } />
@@ -298,6 +358,7 @@ export class CLDVideoLayer extends React.Component<CLDVideoLayerProps, CLDVideoL
298358 panResponder = { this . panResponder }
299359 backButtonPosition = { backButtonPosition }
300360 shareButtonPosition = { shareButtonPosition }
361+ isLandscape = { isLandscape }
301362 />
302363 </ Animated . View >
303364
@@ -306,15 +367,15 @@ export class CLDVideoLayer extends React.Component<CLDVideoLayerProps, CLDVideoL
306367 < >
307368 { onBack && backButtonPosition === ButtonPosition . SE && (
308369 < TouchableOpacity
309- style = { [ styles . topButton , styles . buttonPositionSE ] }
370+ style = { [ responsiveStyles . topButton , responsiveStyles . buttonPositionSE ] }
310371 onPress = { onBack }
311372 >
312373 < Ionicons name = "close" size = { ICON_SIZES . top } color = "white" />
313374 </ TouchableOpacity >
314375 ) }
315376 { shareButtonPosition === ButtonPosition . SE && (
316377 < TouchableOpacity
317- style = { [ styles . topButton , styles . buttonPositionSE ] }
378+ style = { [ responsiveStyles . topButton , responsiveStyles . buttonPositionSE ] }
318379 onPress = { this . handleShare }
319380 >
320381 < Ionicons name = "share-outline" size = { ICON_SIZES . top } color = "white" />
0 commit comments