From 218f4073ec4281eee80bf157b162842e385d88aa Mon Sep 17 00:00:00 2001 From: Sadaqat Ali Date: Sat, 26 Mar 2022 18:14:59 +0500 Subject: [PATCH] added landscape in post screen and orientation lock --- android/app/src/main/AndroidManifest.xml | 3 +-- .../java/app/esteem/mobile/android/MainActivity.java | 8 ++++++++ .../app/esteem/mobile/android/MainApplication.java | 2 ++ ios/Ecency/AppDelegate.m | 4 ++++ ios/Ecency/Info.plist | 2 ++ ios/Podfile.lock | 6 ++++++ package.json | 1 + src/screens/application/index.js | 8 ++++++++ src/screens/post/screen/postScreen.js | 12 +++++++++++- yarn.lock | 5 +++++ 10 files changed, 48 insertions(+), 3 deletions(-) diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 7a51c8c0d..abba2e39c 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -30,8 +30,7 @@ android:name=".MainActivity" android:launchMode="singleTask" android:label="@string/app_name" - android:screenOrientation="portrait" - android:configChanges="keyboard|keyboardHidden|screenSize|uiMode" + android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode" android:windowSoftInputMode="adjustPan"> diff --git a/android/app/src/main/java/app/esteem/mobile/android/MainActivity.java b/android/app/src/main/java/app/esteem/mobile/android/MainActivity.java index 27e4fc5ba..c5664a82f 100644 --- a/android/app/src/main/java/app/esteem/mobile/android/MainActivity.java +++ b/android/app/src/main/java/app/esteem/mobile/android/MainActivity.java @@ -5,6 +5,7 @@ import com.facebook.react.ReactActivityDelegate; import com.facebook.react.ReactRootView; import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView; import android.content.Intent; +import android.content.res.Configuration; public class MainActivity extends ReactActivity { /** @@ -31,4 +32,11 @@ public class MainActivity extends ReactActivity { super.onNewIntent(intent); setIntent(intent); } + + @Override + public void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + Intent intent = new Intent("onConfigurationChanged"); + intent.putExtra("newConfig", newConfig); + this.sendBroadcast(intent); } } diff --git a/android/app/src/main/java/app/esteem/mobile/android/MainApplication.java b/android/app/src/main/java/app/esteem/mobile/android/MainApplication.java index d005b6eb9..bab8e4282 100644 --- a/android/app/src/main/java/app/esteem/mobile/android/MainApplication.java +++ b/android/app/src/main/java/app/esteem/mobile/android/MainApplication.java @@ -12,6 +12,7 @@ import com.facebook.soloader.SoLoader; import androidx.multidex.MultiDexApplication; import com.getkeepsafe.relinker.ReLinker; import com.bugsnag.android.Bugsnag; +import org.wonday.orientation.OrientationActivityLifecycle; //See below, Webview debugging //import android.webkit.WebView; @@ -62,5 +63,6 @@ public class MainApplication extends MultiDexApplication implements ReactApplica SoLoader.init(this, /* native exopackage */ false); // Uncomment below line to Debug Webview // WebView.setWebContentsDebuggingEnabled(true); + registerActivityLifecycleCallbacks(OrientationActivityLifecycle.getInstance()); } } diff --git a/ios/Ecency/AppDelegate.m b/ios/Ecency/AppDelegate.m index 2ba38f5e4..023c4ec99 100644 --- a/ios/Ecency/AppDelegate.m +++ b/ios/Ecency/AppDelegate.m @@ -11,6 +11,7 @@ #import #import #import +#import "Orientation.h" @implementation AppDelegate @@ -60,4 +61,7 @@ return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil]; } +- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { + return [Orientation getOrientation]; +} @end diff --git a/ios/Ecency/Info.plist b/ios/Ecency/Info.plist index 84fe82c41..e222f26b3 100644 --- a/ios/Ecency/Info.plist +++ b/ios/Ecency/Info.plist @@ -115,6 +115,8 @@ UISupportedInterfaceOrientations UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight UIViewControllerBasedStatusBarAppearance diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 043704a79..96fdbd726 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -331,6 +331,8 @@ PODS: - React (~> 0.60) - react-native-netinfo (5.9.10): - React-Core + - react-native-orientation-locker (1.4.0): + - React-Core - react-native-randombytes (3.6.1): - React-Core - react-native-receive-sharing-intent (1.0.4): @@ -508,6 +510,7 @@ DEPENDENCIES: - react-native-date-picker (from `../node_modules/react-native-date-picker`) - react-native-matomo-sdk (from `../node_modules/react-native-matomo-sdk`) - "react-native-netinfo (from `../node_modules/@react-native-community/netinfo`)" + - react-native-orientation-locker (from `../node_modules/react-native-orientation-locker`) - react-native-randombytes (from `../node_modules/react-native-randombytes`) - react-native-receive-sharing-intent (from `../node_modules/react-native-receive-sharing-intent`) - react-native-restart (from `../node_modules/react-native-restart`) @@ -632,6 +635,8 @@ EXTERNAL SOURCES: :path: "../node_modules/react-native-matomo-sdk" react-native-netinfo: :path: "../node_modules/@react-native-community/netinfo" + react-native-orientation-locker: + :path: "../node_modules/react-native-orientation-locker" react-native-randombytes: :path: "../node_modules/react-native-randombytes" react-native-receive-sharing-intent: @@ -760,6 +765,7 @@ SPEC CHECKSUMS: react-native-date-picker: 242eec7af56cea5fb2706d5db5d3837060b3884b react-native-matomo-sdk: 025c54f92e1e26a4d0acee7c3f28cb0fc7e4729c react-native-netinfo: 30fb89fa913c342be82a887b56e96be6d71201dd + react-native-orientation-locker: 2da91e5391971dace445495821c899c111dcad7a react-native-randombytes: 421f1c7d48c0af8dbcd471b0324393ebf8fe7846 react-native-receive-sharing-intent: feba0a332a07977549a85aa58b496eb44368366a react-native-restart: aaad36f3ed7031daac3565f4a79d67e4f3884a50 diff --git a/package.json b/package.json index 701d6d69f..f738b40ae 100644 --- a/package.json +++ b/package.json @@ -108,6 +108,7 @@ "react-native-modal-popover": "^2.1.0", "react-native-modal-translucent": "^5.0.0", "react-native-navigation-bar-color": "^1.0.0", + "react-native-orientation-locker": "^1.4.0", "react-native-os": "^1.0.1", "react-native-permissions": "^3.3.0", "react-native-portalize": "^1.0.7", diff --git a/src/screens/application/index.js b/src/screens/application/index.js index 2e7287f61..e50b51924 100644 --- a/src/screens/application/index.js +++ b/src/screens/application/index.js @@ -1,6 +1,7 @@ import React, { Fragment, useEffect, useState } from 'react'; import SplashScreen from 'react-native-splash-screen'; +import { OrientationLocker, PORTRAIT, LANDSCAPE } from 'react-native-orientation-locker'; import ApplicationContainer from './container/applicationContainer'; import WelcomeScreen from './screen/welcomeScreen'; import ApplicationScreen from './screen/applicationScreen'; @@ -41,6 +42,13 @@ const Application = () => { return ( + console.log('orientation changed : ', orientation)} + onDeviceChange={(orientation) => + console.log('device orientation changed : ', orientation) + } + /> { + useEffect(() => { + return () => Orientation.lockToPortrait(); + }, []); + + useDeviceOrientationChange((orientation) => { + if (orientation === 'LANDSCAPE-RIGHT' || orientation === 'LANDSCAPE-LEFT') { + Orientation.unlockAllOrientations(); + } + }); return (