Skip to content

Commit 84bec75

Browse files
committed
Only change orientation in maestro flows
1 parent 3037b71 commit 84bec75

4 files changed

Lines changed: 33 additions & 13 deletions

File tree

sentry-samples/sentry-samples-android/maestro/orientation_change_flow.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
appId: io.sentry.samples.android
22

33
---
4-
- launchApp
4+
- launchApp:
5+
arguments:
6+
isOrientationChange: true
57
- scrollUntilVisible:
68
element:
79
id: "show_dialog"

sentry-samples/sentry-samples-android/src/main/java/io/sentry/samples/android/MainActivity.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import android.content.res.Configuration;
66
import android.os.Bundle;
77
import android.os.Handler;
8+
import android.util.Log;
89
import androidx.appcompat.app.AlertDialog;
910
import androidx.appcompat.app.AppCompatActivity;
1011
import io.sentry.Attachment;
@@ -40,6 +41,8 @@ public class MainActivity extends AppCompatActivity {
4041
protected void onCreate(Bundle savedInstanceState) {
4142
super.onCreate(savedInstanceState);
4243

44+
SharedState.INSTANCE.setOrientationChange(getIntent().getBooleanExtra("isOrientationChange", false));
45+
Log.e("MainActivity", "isMaestroTest: " + SharedState.INSTANCE.isOrientationChange());
4346
final ActivityMainBinding binding = ActivityMainBinding.inflate(getLayoutInflater());
4447

4548
final File imageFile = getApplicationContext().getFileStreamPath("sentry.png");
@@ -284,14 +287,16 @@ public void run() {
284287
.setPositiveButton(
285288
"Close",
286289
(dialog, which) -> {
287-
int currentOrientation = getResources().getConfiguration().orientation;
288-
if (currentOrientation == Configuration.ORIENTATION_PORTRAIT) {
289-
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
290-
} else if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
291-
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
290+
if (SharedState.INSTANCE.isOrientationChange()) {
291+
int currentOrientation = getResources().getConfiguration().orientation;
292+
if (currentOrientation == Configuration.ORIENTATION_PORTRAIT) {
293+
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
294+
} else if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
295+
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
296+
}
297+
} else {
298+
dialog.dismiss();
292299
}
293-
294-
//dialog.dismiss();
295300
})
296301
.show();
297302
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package io.sentry.samples.android
2+
3+
object SharedState {
4+
@Volatile
5+
var isOrientationChange: Boolean = false
6+
}

sentry-samples/sentry-samples-android/src/main/java/io/sentry/samples/android/compose/ComposeActivity.kt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import io.sentry.android.replay.sentryReplayUnmask
5353
import io.sentry.compose.SentryTraced
5454
import io.sentry.compose.withSentryObservableEffect
5555
import io.sentry.samples.android.GithubAPI
56+
import io.sentry.samples.android.SharedState
5657
import kotlinx.coroutines.launch
5758
import io.sentry.samples.android.R as IR
5859

@@ -125,11 +126,17 @@ fun Landing(
125126
if (showDialog) {
126127
BasicAlertDialog(
127128
onDismissRequest = {
128-
val orientation = activity.resources.configuration.orientation
129-
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
130-
activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
131-
} else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
132-
activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
129+
if (SharedState.isOrientationChange) {
130+
val orientation = activity.resources.configuration.orientation
131+
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
132+
activity.requestedOrientation =
133+
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
134+
} else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
135+
activity.requestedOrientation =
136+
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
137+
}
138+
} else {
139+
showDialog = false
133140
}
134141
},
135142
content = {

0 commit comments

Comments
 (0)