-
Notifications
You must be signed in to change notification settings - Fork 5.8k
fix(mobile): stop Android desktop windows from clipping text #8200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mrmg
wants to merge
5
commits into
pingdotgg:main
Choose a base branch
from
mrmg:fix/android-windowed-desktop-scaling
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c2be54f
fix(mobile): stop Android desktop windows from clipping text
mrmg 2cd238f
fix(mobile): paint Android sidebar title with page-title metrics
mrmg 5f3215a
fix(mobile): restore TalkBack heading on Android sidebar title
mrmg 5ad82f3
test(mobile): lock Android window title contracts
mrmg 590e685
Merge remote-tracking branch 'pingdotgg/main' into fix/android-window…
mrmg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| import * as NodeModule from "node:module"; | ||
| import { describe, expect, it } from "vite-plus/test"; | ||
|
|
||
| import { | ||
| ANDROID_TABLET_SMALLEST_WIDTH_DP, | ||
| ANDROID_UI_MODE_TYPE_CAR, | ||
| ANDROID_UI_MODE_TYPE_DESK, | ||
| ANDROID_UI_MODE_TYPE_NORMAL, | ||
| shouldUnlockAndroidScreenOrientation, | ||
| } from "./androidWindowing"; | ||
|
|
||
| const require = NodeModule.createRequire(import.meta.url); | ||
| const { patchMainActivity } = require("../../plugins/withAndroidTabletOrientation.cjs") as { | ||
| patchMainActivity: (contents: string) => string; | ||
| }; | ||
|
|
||
| const EXPO_MAIN_ACTIVITY = `package com.t3tools.t3code | ||
| import android.os.Bundle | ||
| import com.facebook.react.ReactActivity | ||
|
|
||
| class MainActivity : ReactActivity() { | ||
| override fun onCreate(savedInstanceState: Bundle?) { | ||
| super.onCreate(null) | ||
| } | ||
| } | ||
| `; | ||
|
|
||
| const LEGACY_MAIN_ACTIVITY = `package com.t3tools.t3code | ||
| import android.os.Bundle | ||
| import android.content.pm.ActivityInfo | ||
| import android.content.res.Configuration | ||
| import com.facebook.react.ReactActivity | ||
|
|
||
| class MainActivity : ReactActivity() { | ||
| // Applied in onCreate and re-applied on fold/unfold; added by | ||
| // withAndroidTabletOrientation. | ||
| override fun onConfigurationChanged(newConfig: Configuration) { | ||
| super.onConfigurationChanged(newConfig) | ||
| applyTabletOrientation() | ||
| } | ||
|
|
||
| private fun applyTabletOrientation() { | ||
| requestedOrientation = if (resources.configuration.smallestScreenWidthDp >= 600) { | ||
| ActivityInfo.SCREEN_ORIENTATION_FULL_USER | ||
| } else { | ||
| ActivityInfo.SCREEN_ORIENTATION_PORTRAIT | ||
| } | ||
| } | ||
| override fun onCreate(savedInstanceState: Bundle?) { | ||
| super.onCreate(null) | ||
| applyTabletOrientation() | ||
| } | ||
| } | ||
| `; | ||
|
|
||
| describe("shouldUnlockAndroidScreenOrientation", () => { | ||
| it("keeps phones in the portrait manifest lock", () => { | ||
| expect( | ||
| shouldUnlockAndroidScreenOrientation({ | ||
| smallestScreenWidthDp: 411, | ||
| uiModeType: ANDROID_UI_MODE_TYPE_NORMAL, | ||
| }), | ||
| ).toBe(false); | ||
| }); | ||
|
|
||
| it("unlocks foldables and tablets at the 600dp smallest-width breakpoint", () => { | ||
| expect( | ||
| shouldUnlockAndroidScreenOrientation({ | ||
| smallestScreenWidthDp: ANDROID_TABLET_SMALLEST_WIDTH_DP, | ||
| uiModeType: ANDROID_UI_MODE_TYPE_NORMAL, | ||
| }), | ||
| ).toBe(true); | ||
| expect( | ||
| shouldUnlockAndroidScreenOrientation({ | ||
| smallestScreenWidthDp: ANDROID_TABLET_SMALLEST_WIDTH_DP - 1, | ||
| uiModeType: ANDROID_UI_MODE_TYPE_NORMAL, | ||
| }), | ||
| ).toBe(false); | ||
| }); | ||
|
|
||
| it("unlocks desktop windows (DeX, Pixel Desktop, ChromeOS) even when smallest width is phone-sized", () => { | ||
| expect( | ||
| shouldUnlockAndroidScreenOrientation({ | ||
| smallestScreenWidthDp: 411, | ||
| uiModeType: ANDROID_UI_MODE_TYPE_DESK, | ||
| }), | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| it("does not treat other UI modes as desktop", () => { | ||
| expect( | ||
| shouldUnlockAndroidScreenOrientation({ | ||
| smallestScreenWidthDp: 411, | ||
| uiModeType: ANDROID_UI_MODE_TYPE_CAR, | ||
| }), | ||
| ).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe("withAndroidTabletOrientation MainActivity patch", () => { | ||
| it("unlocks desk-mode windows and rebinds display metrics from the activity", () => { | ||
| const patched = patchMainActivity(EXPO_MAIN_ACTIVITY); | ||
| expect(patched).toContain("UI_MODE_TYPE_DESK"); | ||
| expect(patched).toContain(`smallestScreenWidthDp >= ${ANDROID_TABLET_SMALLEST_WIDTH_DP}`); | ||
| expect(patched).toContain("DisplayMetricsHolder.initDisplayMetrics(this)"); | ||
| expect(patched).toContain("applyWindowedOrientation()"); | ||
| expect(patched).toContain("rebindWindowDisplayMetrics()"); | ||
| }); | ||
|
|
||
| it("emits the complete phone/tablet/desk policy and configuration rebind path", () => { | ||
| const patched = patchMainActivity(EXPO_MAIN_ACTIVITY); | ||
| expect(patched).toContain(`val uiModeType = config.uiMode and Configuration.UI_MODE_TYPE_MASK`); | ||
| expect(patched).toContain( | ||
| `val unlockOrientation =\n config.smallestScreenWidthDp >= ${ANDROID_TABLET_SMALLEST_WIDTH_DP} || uiModeType == Configuration.UI_MODE_TYPE_DESK`, | ||
| ); | ||
| expect(patched).toContain( | ||
| `if (unlockOrientation) {\n ActivityInfo.SCREEN_ORIENTATION_FULL_USER\n } else {\n ActivityInfo.SCREEN_ORIENTATION_PORTRAIT`, | ||
| ); | ||
| expect(patched).toContain( | ||
| "DisplayMetricsHolder.initDisplayMetrics(this)\n window.decorView.post { window.decorView.requestLayout() }", | ||
| ); | ||
| expect(patched).toContain( | ||
| "super.onConfigurationChanged(newConfig)\n applyWindowedOrientation()\n rebindWindowDisplayMetrics()", | ||
| ); | ||
| }); | ||
|
|
||
| it("replaces the tablet-only injection on existing MainActivity files", () => { | ||
| const patched = patchMainActivity(LEGACY_MAIN_ACTIVITY); | ||
| expect(patched).not.toContain("applyTabletOrientation"); | ||
| expect(patched).toContain("UI_MODE_TYPE_DESK"); | ||
| expect(patched).toContain("DisplayMetricsHolder.initDisplayMetrics(this)"); | ||
| expect(patched).toContain("applyWindowedOrientation()\n rebindWindowDisplayMetrics()"); | ||
| }); | ||
|
|
||
| it("is idempotent", () => { | ||
| const once = patchMainActivity(EXPO_MAIN_ACTIVITY); | ||
| expect(patchMainActivity(once)).toBe(once); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /** | ||
| * Android windowing policy for orientation. The Kotlin in | ||
| * `plugins/withAndroidTabletOrientation.cjs` must stay in lockstep with this | ||
| * function: phones stay portrait-locked, everything else that is a real | ||
| * window (tablet/fold inner screen, DeX, Pixel Desktop, ChromeOS) unlocks. | ||
| * | ||
| * `uiModeType` is `Configuration.uiMode & UI_MODE_TYPE_MASK`. | ||
| */ | ||
| export const ANDROID_TABLET_SMALLEST_WIDTH_DP = 600; | ||
|
|
||
| /** `android.content.res.Configuration.UI_MODE_TYPE_NORMAL` */ | ||
| export const ANDROID_UI_MODE_TYPE_NORMAL = 1; | ||
| /** `android.content.res.Configuration.UI_MODE_TYPE_DESK` — DeX, Pixel Desktop, ChromeOS. */ | ||
| export const ANDROID_UI_MODE_TYPE_DESK = 2; | ||
| /** `android.content.res.Configuration.UI_MODE_TYPE_CAR` */ | ||
| export const ANDROID_UI_MODE_TYPE_CAR = 3; | ||
|
|
||
| export function shouldUnlockAndroidScreenOrientation(input: { | ||
| readonly smallestScreenWidthDp: number; | ||
| readonly uiModeType: number; | ||
| }): boolean { | ||
| if (input.smallestScreenWidthDp >= ANDROID_TABLET_SMALLEST_WIDTH_DP) { | ||
| return true; | ||
| } | ||
| return input.uiModeType === ANDROID_UI_MODE_TYPE_DESK; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.