From fb2cfaa204734a68e376d9a53c567eec4a0d2c74 Mon Sep 17 00:00:00 2001 From: Horatiu Muresan Date: Wed, 21 Sep 2022 13:17:06 +0300 Subject: [PATCH] fix(carmode) Force portrait when in carmode --- android/sdk/build.gradle | 1 + .../org/jitsi/meet/sdk/JitsiMeetActivity.java | 11 +++++++++++ .../meet/sdk/ReactInstanceManagerHolder.java | 1 + android/settings.gradle | 2 ++ ios/Podfile.lock | 6 ++++++ ios/app/src/AppDelegate.m | 6 ++++++ ios/sdk/src/JitsiMeet.h | 3 +++ ios/sdk/src/JitsiMeet.m | 5 +++++ package-lock.json | 16 ++++++++++++++++ package.json | 1 + .../components/native/carmode/CarMode.tsx | 3 +++ 11 files changed, 55 insertions(+) diff --git a/android/sdk/build.gradle b/android/sdk/build.gradle index 68a3d8928..05517986f 100644 --- a/android/sdk/build.gradle +++ b/android/sdk/build.gradle @@ -77,6 +77,7 @@ dependencies { implementation project(':react-native-immersive') implementation project(':react-native-keep-awake') implementation project(':react-native-masked-view_masked-view') + implementation project(':react-native-orientation-locker') implementation project(':react-native-pager-view') implementation project(':react-native-performance') implementation project(':react-native-safe-area-context') diff --git a/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetActivity.java b/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetActivity.java index e1a6d56b9..5644916e6 100644 --- a/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetActivity.java +++ b/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetActivity.java @@ -21,6 +21,7 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.content.res.Configuration; import android.net.Uri; import android.os.Bundle; @@ -30,6 +31,7 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager; import com.facebook.react.modules.core.PermissionListener; +import org.wonday.orientation.OrientationActivityLifecycle; import org.jitsi.meet.sdk.log.JitsiMeetLogger; import java.util.HashMap; @@ -86,6 +88,14 @@ public class JitsiMeetActivity extends AppCompatActivity // Overrides // + @Override + public void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + Intent intent = new Intent("onConfigurationChanged"); + intent.putExtra("newConfig", newConfig); + this.sendBroadcast(intent); + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -94,6 +104,7 @@ public class JitsiMeetActivity extends AppCompatActivity this.jitsiView = findViewById(R.id.jitsiView); registerForBroadcastMessages(); + registerActivityLifecycleCallbacks(OrientationActivityLifecycle.getInstance()); if (!extraInitialize()) { initialize(); diff --git a/android/sdk/src/main/java/org/jitsi/meet/sdk/ReactInstanceManagerHolder.java b/android/sdk/src/main/java/org/jitsi/meet/sdk/ReactInstanceManagerHolder.java index 522c46cd5..90d09d5d2 100644 --- a/android/sdk/src/main/java/org/jitsi/meet/sdk/ReactInstanceManagerHolder.java +++ b/android/sdk/src/main/java/org/jitsi/meet/sdk/ReactInstanceManagerHolder.java @@ -129,6 +129,7 @@ class ReactInstanceManagerHolder { new com.zmxv.RNSound.RNSoundPackage(), new com.th3rdwave.safeareacontext.SafeAreaContextPackage(), new com.horcrux.svg.SvgPackage(), + new org.wonday.orientation.OrientationPackage(), new ReactPackageAdapter() { @Override public List createNativeModules(ReactApplicationContext reactContext) { diff --git a/android/settings.gradle b/android/settings.gradle index e3744b104..d54b52ee2 100644 --- a/android/settings.gradle +++ b/android/settings.gradle @@ -33,6 +33,8 @@ include ':react-native-keep-awake' project(':react-native-keep-awake').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-keep-awake/android') include ':react-native-masked-view_masked-view' project(':react-native-masked-view_masked-view').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-masked-view/masked-view/android') +include ':react-native-orientation-locker' +project(':react-native-orientation-locker').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-orientation-locker/android') include ':react-native-pager-view' project(':react-native-pager-view').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-pager-view/android') include ':react-native-performance' diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 0c56aba68..f655b90fe 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -366,6 +366,8 @@ PODS: - React - react-native-netinfo (7.1.7): - React-Core + - react-native-orientation-locker (1.5.0): + - React-Core - react-native-pager-view (5.4.9): - React-Core - react-native-performance (2.1.0): @@ -514,6 +516,7 @@ DEPENDENCIES: - react-native-get-random-values (from `../node_modules/react-native-get-random-values`) - react-native-keep-awake (from `../node_modules/react-native-keep-awake`) - "react-native-netinfo (from `../node_modules/@react-native-community/netinfo`)" + - react-native-orientation-locker (from `../node_modules/react-native-orientation-locker`) - react-native-pager-view (from `../node_modules/react-native-pager-view`) - react-native-performance (from `../node_modules/react-native-performance/ios`) - react-native-safe-area-context (from `../node_modules/react-native-safe-area-context`) @@ -623,6 +626,8 @@ EXTERNAL SOURCES: :path: "../node_modules/react-native-keep-awake" react-native-netinfo: :path: "../node_modules/@react-native-community/netinfo" + react-native-orientation-locker: + :path: "../node_modules/react-native-orientation-locker" react-native-pager-view: :path: "../node_modules/react-native-pager-view" react-native-performance: @@ -738,6 +743,7 @@ SPEC CHECKSUMS: react-native-get-random-values: 30b3f74ca34e30e2e480de48e4add2706a40ac8f react-native-keep-awake: afad8a51dfef9fe9655a6344771be32c8596d774 react-native-netinfo: 27f287f2d191693f3b9d01a4273137fcf91c3b5d + react-native-orientation-locker: 851f6510d8046ea2f14aa169b1e01fcd309a94ba react-native-pager-view: 3ee7d4c7697fb3ef788346e834a60cca97ed8540 react-native-performance: f4b6604a9d5a8a7407e34a82fab6c641d9a3ec12 react-native-safe-area-context: 584dc04881deb49474363f3be89e4ca0e854c057 diff --git a/ios/app/src/AppDelegate.m b/ios/app/src/AppDelegate.m index 3e39ec494..634c199ea 100644 --- a/ios/app/src/AppDelegate.m +++ b/ios/app/src/AppDelegate.m @@ -124,4 +124,10 @@ options:options]; } +- (UIInterfaceOrientationMask)application:(UIApplication *)application + supportedInterfaceOrientationsForWindow:(UIWindow *)window { + return [[JitsiMeet sharedInstance] application:application + supportedInterfaceOrientationsForWindow:window]; +} + @end diff --git a/ios/sdk/src/JitsiMeet.h b/ios/sdk/src/JitsiMeet.h index d9e6ddd16..6e3505d8f 100644 --- a/ios/sdk/src/JitsiMeet.h +++ b/ios/sdk/src/JitsiMeet.h @@ -57,6 +57,9 @@ openURL:(NSURL *_Nonnull)url options:(NSDictionary *_Nonnull)options; +- (UIInterfaceOrientationMask)application:(UIApplication *)application + supportedInterfaceOrientationsForWindow:(UIWindow *)window; + #pragma mark - Utility methods /** diff --git a/ios/sdk/src/JitsiMeet.m b/ios/sdk/src/JitsiMeet.m index ddca35d82..d394e655e 100644 --- a/ios/sdk/src/JitsiMeet.m +++ b/ios/sdk/src/JitsiMeet.m @@ -16,6 +16,7 @@ #import #import +#import "Orientation.h" #import "JitsiMeet+Private.h" #import "JitsiMeetConferenceOptions+Private.h" @@ -127,6 +128,10 @@ return true; } +- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { + return [Orientation getOrientation]; +} + #pragma mark - Utility methods - (void)instantiateReactNativeBridge { diff --git a/package-lock.json b/package-lock.json index 9ab4009ce..07289f329 100644 --- a/package-lock.json +++ b/package-lock.json @@ -99,6 +99,7 @@ "react-native-get-random-values": "1.7.2", "react-native-immersive": "2.0.0", "react-native-keep-awake": "4.0.0", + "react-native-orientation-locker": "^1.5.0", "react-native-pager-view": "5.4.9", "react-native-paper": "4.11.1", "react-native-performance": "2.1.0", @@ -15915,6 +15916,16 @@ "resolved": "https://registry.npmjs.org/react-native-keep-awake/-/react-native-keep-awake-4.0.0.tgz", "integrity": "sha512-0Fotox+eLXQooeibVs3P60yASYUWjtRw9MZNmbuHt5UZQrgUrAKsE4jm7gTr4tPU1m1RkwGzcgUFpcOkh/ec7g==" }, + "node_modules/react-native-orientation-locker": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/react-native-orientation-locker/-/react-native-orientation-locker-1.5.0.tgz", + "integrity": "sha512-4XOCGmNN4BXg5JUFjUuXpsfhPJmbA3LkQilJO1ed+6vL97teTdG2w5IEevKiqL9/hPjeWE8YYtX/YW+yp53hkg==", + "peerDependencies": { + "react": ">=16.13.1", + "react-native": ">=0.63.2", + "react-native-windows": ">=0.63.3" + } + }, "node_modules/react-native-pager-view": { "version": "5.4.9", "resolved": "https://registry.npmjs.org/react-native-pager-view/-/react-native-pager-view-5.4.9.tgz", @@ -32503,6 +32514,11 @@ "resolved": "https://registry.npmjs.org/react-native-keep-awake/-/react-native-keep-awake-4.0.0.tgz", "integrity": "sha512-0Fotox+eLXQooeibVs3P60yASYUWjtRw9MZNmbuHt5UZQrgUrAKsE4jm7gTr4tPU1m1RkwGzcgUFpcOkh/ec7g==" }, + "react-native-orientation-locker": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/react-native-orientation-locker/-/react-native-orientation-locker-1.5.0.tgz", + "integrity": "sha512-4XOCGmNN4BXg5JUFjUuXpsfhPJmbA3LkQilJO1ed+6vL97teTdG2w5IEevKiqL9/hPjeWE8YYtX/YW+yp53hkg==" + }, "react-native-pager-view": { "version": "5.4.9", "resolved": "https://registry.npmjs.org/react-native-pager-view/-/react-native-pager-view-5.4.9.tgz", diff --git a/package.json b/package.json index 1d6b7dc6c..3329b170c 100644 --- a/package.json +++ b/package.json @@ -104,6 +104,7 @@ "react-native-get-random-values": "1.7.2", "react-native-immersive": "2.0.0", "react-native-keep-awake": "4.0.0", + "react-native-orientation-locker": "^1.5.0", "react-native-pager-view": "5.4.9", "react-native-paper": "4.11.1", "react-native-performance": "2.1.0", diff --git a/react/features/conference/components/native/carmode/CarMode.tsx b/react/features/conference/components/native/carmode/CarMode.tsx index 8d10339b6..06d252ec8 100644 --- a/react/features/conference/components/native/carmode/CarMode.tsx +++ b/react/features/conference/components/native/carmode/CarMode.tsx @@ -1,6 +1,7 @@ /* eslint-disable lines-around-comment */ import React, { useEffect } from 'react'; import { View } from 'react-native'; +import Orientation from 'react-native-orientation-locker'; import { withSafeAreaInsets } from 'react-native-safe-area-context'; import { useDispatch, useSelector } from 'react-redux'; @@ -38,8 +39,10 @@ const CarMode = (): JSX.Element => { useEffect(() => { dispatch(setIsCarmode(true)); setPictureInPictureEnabled(false); + Orientation.lockToPortrait(); return () => { + Orientation.unlockAllOrientations(); dispatch(setIsCarmode(false)); if (!isSharing) { setPictureInPictureEnabled(true);