@@ -34,6 +34,7 @@ var react_native_1 = require("react-native");
3434var react_native_navigation_1 = require ( "react-native-navigation" ) ;
3535/* Utils - Project Utilities */
3636var events_1 = require ( "./events" ) ;
37+ var MaxWidthOnLandscapeMode = 300 ;
3738var DirectionType ;
3839( function ( DirectionType ) {
3940 DirectionType [ "left" ] = "left" ;
@@ -76,7 +77,9 @@ var RNNDrawer = /** @class */ (function () {
7677 return value ;
7778 } ;
7879 /** Component Variables */
79- _this . drawerWidth = _resolveDrawerSize ( props . drawerScreenWidth , _this . screenWidth ) ;
80+ _this . drawerWidth = _this . isLandscape ( )
81+ ? MaxWidthOnLandscapeMode
82+ : _resolveDrawerSize ( props . drawerScreenWidth , _this . screenWidth ) ;
8083 _this . drawerHeight = _resolveDrawerSize ( props . drawerScreenHeight , _this . screenHeight ) ;
8184 _this . drawerOpenedValues = {
8285 left : 0 ,
@@ -96,15 +99,24 @@ var RNNDrawer = /** @class */ (function () {
9699 sideMenuOverlayOpacity : new react_native_1 . Animated . Value ( 0 ) ,
97100 sideMenuSwipingStarted : false ,
98101 sideMenuIsDismissing : false ,
102+ screenHeight : _this . screenHeight ,
99103 } ;
100104 /** Component Bindings */
101105 _this . touchedOutside = _this . touchedOutside . bind ( _this ) ;
102106 _this . dismissDrawerWithAnimation = _this . dismissDrawerWithAnimation . bind ( _this ) ;
103107 _this . registerListeners = _this . registerListeners . bind ( _this ) ;
104108 _this . removeListeners = _this . removeListeners . bind ( _this ) ;
109+ _this . isLandscape = _this . isLandscape . bind ( _this ) ;
105110 react_native_navigation_1 . Navigation . events ( ) . bindComponent ( _this ) ;
106111 return _this ;
107112 }
113+ /**
114+ * Check if device is in landscape mode
115+ */
116+ WrappedDrawer . prototype . isLandscape = function ( ) {
117+ var dim = react_native_1 . Dimensions . get ( 'window' ) ;
118+ return dim . height <= dim . width ;
119+ } ;
108120 /**
109121 * [ Built-in React method. ]
110122 *
@@ -155,6 +167,18 @@ var RNNDrawer = /** @class */ (function () {
155167 var _this = this ;
156168 /** Props */
157169 var _a = this . props , direction = _a . direction , fadeOpacity = _a . fadeOpacity ;
170+ // Adapt the drawer's size on orientation change
171+ react_native_1 . Dimensions . addEventListener ( "change" , function ( _a ) {
172+ var window = _a . window ;
173+ var screenHeight = window . height ;
174+ _this . setState ( { screenHeight : screenHeight } ) ;
175+ // Apply correct position if opened from right
176+ if ( _this . props . direction === "right" ) {
177+ // Calculates the position of the drawer from the left side of the screen
178+ var alignedMovementValue = window . width - _this . drawerWidth ;
179+ _this . state . sideMenuOpenValue . setValue ( alignedMovementValue ) ;
180+ }
181+ } ) ;
158182 // Executes when the side of the screen interaction starts
159183 this . unsubscribeSwipeStart = events_1 . listen ( 'SWIPE_START' , function ( ) {
160184 _this . setState ( {
@@ -226,6 +250,7 @@ var RNNDrawer = /** @class */ (function () {
226250 * Removes all the listenrs from this component
227251 */
228252 WrappedDrawer . prototype . removeListeners = function ( ) {
253+ react_native_1 . Dimensions . removeEventListener ( "change" , function ( ) { } ) ;
229254 if ( this . unsubscribeSwipeStart )
230255 this . unsubscribeSwipeStart ( ) ;
231256 if ( this . unsubscribeSwipeMove )
@@ -260,7 +285,7 @@ var RNNDrawer = /** @class */ (function () {
260285 React . createElement ( react_native_1 . Animated . View , { style : [
261286 { backgroundColor : '#FFF' } ,
262287 style ,
263- __assign ( { height : this . drawerHeight , width : this . drawerWidth } , animatedValue ) ,
288+ __assign ( { height : this . state . screenHeight , width : this . drawerWidth } , animatedValue ) ,
264289 ] } ,
265290 React . createElement ( Component , __assign ( { } , this . props ) ) ) ) ) ;
266291 } ;
0 commit comments