feat(android): opt-in Partial Custom Tab via androidCustomTabPartialHeightFraction#1119
feat(android): opt-in Partial Custom Tab via androidCustomTabPartialHeightFraction#1119omeratt wants to merge 2 commits into
Conversation
…eightFraction Adds an optional fraction-based config that renders the Chrome Custom Tab as a user-resizable bottom sheet on Chrome 107+, matching the modal feel of iOS's ASWebAuthenticationSession. When omitted, behavior is unchanged. - index.d.ts: new optional `androidCustomTabPartialHeightFraction: number` - index.js: validation (must be a number in (0, 1]) + Android-only bridge arg - RNAppAuthModule.java: threads the fraction through `authorize` and `authorizeWithConfiguration`; between `createCustomTabsIntentBuilder()` and `build()`, calls `setInitialActivityHeightPx(displayHeight * fraction, ACTIVITY_HEIGHT_ADJUSTABLE)` when the fraction is non-null and the request is not a Trusted Web Activity - android/build.gradle: bump androidx.browser:browser 1.4.0 -> 1.5.0 for the setInitialActivityHeightPx API - docs/usage/config.md: documents the new option, the Chrome 107+ floor, and the prefetchConfiguration warmup recommendation for first-launch - index.spec.js: 5 new tests for the option (valid fraction passthrough, default null, invalid type, fraction <= 0, fraction > 1) + updates the existing 5 native-bridge assertions to include the new positional arg - changeset: minor bump (additive, opt-in, backward compatible)
🦋 Changeset detectedLatest commit: 14239ab The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
@omeratt is attempting to deploy a commit to the formidable-labs Team on Vercel. A member of the Team first needs to authorize it. |
… non-Chrome browsers, compileSdk 33+)
There was a problem hiding this comment.
Pull request overview
This PR adds an Android-only, opt-in configuration option (androidCustomTabPartialHeightFraction) to present the authorization Chrome Custom Tab as a user-resizable bottom sheet (Partial Custom Tabs on Chrome 107+), improving UX parity with iOS while keeping default behavior unchanged when unset.
Changes:
- Adds
androidCustomTabPartialHeightFraction?: numberto the publicAuthConfigurationTypeScript type and documents its behavior and caveats. - Validates the fraction in JS (
(0, 1]) and forwards it as an additional Android-only positional argument over the native bridge. - Wires the fraction through the Android native module and sets the Partial Custom Tab initial height via
setInitialActivityHeightPx, plus updates tests and bumpsandroidx.browser:browserto1.5.0.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
packages/react-native-app-auth/index.d.ts |
Adds the new optional config field to the public TS API. |
packages/react-native-app-auth/index.js |
Validates the fraction and forwards it to the Android native bridge. |
packages/react-native-app-auth/android/build.gradle |
Bumps androidx.browser:browser to enable the Partial Custom Tabs API. |
packages/react-native-app-auth/android/src/main/java/com/rnappauth/RNAppAuthModule.java |
Applies the partial height fraction to the Custom Tab builder (when applicable). |
packages/react-native-app-auth/index.spec.js |
Updates bridge argument assertions and adds Android-specific validation/forwarding tests. |
docs/docs/usage/config.md |
Documents the new option, platform/version constraints, and prefetch recommendation. |
.changeset/android-partial-custom-tabs.md |
Declares a minor version bump for the additive feature. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (!androidTrustedWebActivity && androidCustomTabPartialHeightFraction != null) { | ||
| int displayHeightPx = currentActivity.getResources().getDisplayMetrics().heightPixels; | ||
| int initialHeightPx = (int) (displayHeightPx * androidCustomTabPartialHeightFraction); | ||
| intentBuilder.setInitialActivityHeightPx(initialHeightPx, CustomTabsIntent.ACTIVITY_HEIGHT_ADJUSTABLE); | ||
| } |
| expect(lastArg).toBe(0.85); | ||
| }); | ||
|
|
||
| it('forwards null when omitted', () => { |
Fixes #1118
Description
Adds an opt-in
androidCustomTabPartialHeightFractionAuthConfigurationfield that, on Chrome 107+, renders the authorization Chrome Custom Tab as
a user-resizable bottom sheet at the caller-specified fraction of the
screen height — matching the modal feel of iOS's
ASWebAuthenticationSession. See #1118 for the UX motivation andside-by-side screenshots.
The feature is gracefully degrading and zero-regression:
Custom Tab as today.
(0, 1]→ betweenauthService.createCustomTabsIntentBuilder()and.build(), thelibrary calls
setInitialActivityHeightPx(displayHeight * fraction, CustomTabsIntent.ACTIVITY_HEIGHT_ADJUSTABLE).Older Chrome silently ignores the extra and falls back to the
full-screen Custom Tab — no crash, no warning, no behavior surprise.
androidTrustedWebActivityis true (TWAs intentionallyrender full-screen).
What changed
packages/react-native-app-auth/index.d.tsandroidCustomTabPartialHeightFraction?: numberonAuthConfiguration.packages/react-native-app-auth/index.js(0, 1], otherwiseinvariantthrows); Android-only positional argument to the native bridge. iOS path is untouched (Platform.OS === 'android'guard).packages/react-native-app-auth/android/build.gradleandroidx.browser:browser1.4.0 → 1.5.0for thesetInitialActivityHeightPxAPI.packages/react-native-app-auth/android/src/main/java/com/rnappauth/RNAppAuthModule.javaauthorizeandauthorizeWithConfiguration; conditionally callssetInitialActivityHeightPxbetween builder creation and.build().packages/react-native-app-auth/index.spec.jsnull; throw on non-number; throw on≤ 0; throw on> 1). Updates the existing 5 native-bridge assertions to include the new positional arg.docs/docs/usage/config.mdprefetchConfigurationwarmup recommendation needed for the bottom sheet to render on the first invocation..changeset/android-partial-custom-tabs.mdUsage
Steps to verify
yarn installat the repo root, then inpackages/react-native-app-auth/:yarn lint→ passes (no new warnings introduced by this PR).yarn test→ 78 tests pass, including 5 new tests forandroidCustomTabPartialHeightFractionvalidation + native-bridgepassthrough.
repo's CI emulator at API 35 ships Chrome 147, which works). Add
androidCustomTabPartialHeightFraction: 0.85to the example config andcall
prefetchConfigurationon screen mount, then tap the authorizebutton → the Chrome Custom Tab renders as a bottom sheet at ~85% of the
screen height; the host activity is visible behind it; the user can
drag the sheet up to full-screen via the handle. Cancel via the X
button → returns to the host app.
androidCustomTabPartialHeightFractionunset, the flow renders full-screen exactly as before this PR.
ignored (TWA renders full-screen as before).
import { AuthConfiguration }and try{ androidCustomTabPartialHeightFraction: 0.85 } satisfies AuthConfiguration→ typechecks;
{ androidCustomTabPartialHeightFraction: 'half' }→type error. Confirms the
index.d.tschange is correct.Tests, README, and TypeScript definitions are updated.