Skip to content

Refactor/src dry kiss srp nitro 035#90

Merged
mCodex merged 12 commits intomainfrom
refactor/src-dry-kiss-srp-nitro-035
Apr 22, 2026
Merged

Refactor/src dry kiss srp nitro 035#90
mCodex merged 12 commits intomainfrom
refactor/src-dry-kiss-srp-nitro-035

Conversation

@mCodex
Copy link
Copy Markdown
Owner

@mCodex mCodex commented Apr 22, 2026

This pull request introduces several improvements and refactorings across the codebase, focusing on modernizing the API, enhancing Android compatibility, improving accessibility support, and updating documentation and configuration files. The most important changes are summarized below.


API Refactor and Documentation Updates

  • Migrated from the static InAppBrowser class to named exports (open, openAuth, close, closeAuth, isAvailable) for better tree shaking and modern usage; updated all relevant documentation and example usages to reflect this change. [1] [2] [3] [4] [5]
  • Updated documentation to clarify that the native module wrapper implementation is now in src/core/native.ts instead of src/core/InAppBrowser.ts.

Android Platform Improvements

  • Improved context handling in HybridInappbrowserNitro.kt for more reliable activity resolution and ensured that the browser closes correctly by relying on user navigation, with explanatory comments. [1] [2] [3]
  • Enhanced error handling for package checks in CustomTabsPackageHelper.kt and added suppression for deprecated API usage.
  • Improved accessibility support for high-contrast detection in DynamicColorResolver.kt, using reflection only on supported Android versions and providing a safe fallback. [1] [2]

Dependency and Build System Updates

  • Added androidx.core:core as a dependency in android/build.gradle to improve Android compatibility.
  • Updated JNI initialization in cpp-adapter.cpp to use fbjni for improved JNI registration and initialization.

Example and Formatting Configuration

  • Refactored the example app for improved readability, accessibility, and log handling, and removed unused configuration files (.eslintrc.js, .prettierrc.js). [1] [2] [3] [4] [5] [6] [7]
  • Added a biome.json configuration file for project-wide formatting and linting, replacing previous tooling.

Funding and Project Metadata

  • Added a .github/FUNDING.yml file to support multiple funding platforms.

These changes modernize the library's API, improve Android and accessibility support, and update project configuration for better maintainability.

mCodex and others added 9 commits March 9, 2026 10:01
…king

- Extract all domain types/enums from spec into src/types.ts (SRP)
- Slim spec file to HybridObject bridge contract only
- Replace InAppBrowser static class with named function exports (tree shaking)
- Use getHybridObjectConstructor from Nitro 0.35 — removes hand-rolled caching
- Remove mapOptions alias (DRY)
- Fix utils/options.ts: re-import from ../types, remove @ts-expect-error casts
- Narrow useInAppBrowser hook: only open/openAuth use runSafely (SRP)
- Clean index.ts: no class mutation, explicit export type separations
- Update README for v3 named exports API + add migration guide

BREAKING CHANGE: InAppBrowser.method() replaced by named imports
iOS:
- Remove DispatchQueue.main.sync deadlock risk — mark nitroTopMostViewController @mainactor
- Drop SFAuthenticationSession (iOS 11 dead code) — ASWebAuthenticationSession only
- Remove all #available(iOS 13.0, *) guards (unreachable at iOS 16+ deployment target)
- Simplify AuthSessionManager to single session property, 2-line cancel()

Android:
- Fix self-referential applicationContext getter — single NitroModules.applicationContext call
- Lift Chrome-only Custom Tabs restriction — any provider (Samsung, Firefox, Brave, Edge) now works
- Replace private reflection for high-contrast detection with public AccessibilityManager API (API 31+)
- Fix deprecated getPackageInfo(name, 0) — use PackageInfoCompat with Long flags
- Document close()/closeAuth() no-ops as intentional
…ects flag

refactor: Enhance native.ts with lazy initialization for hybrid object and improve URL validation

refactor: Optimize useInAppBrowser hook for better loading and error handling

fix: Update index.ts to export types correctly and streamline imports

chore: Refactor types.ts for consistency and clarity in type definitions

refactor: Improve options sanitization in utils/options.ts for cleaner code

fix: Enhance URL validation logic in utils/url.ts for better error handling

chore: Update yarn.lock to include biomejs for improved linting and formatting

Co-authored-by: Copilot <copilot@github.com>
Add a top-level biome.json for formatting/linting and remove example/biome.json; update .gitignore to ignore stray TS/TSX/JS build outputs. Reformat and clean up example sources (App.tsx, index.js, babel.config.js) — style tweaks, import/path normalization, remove extra empty tokens, and refactor example logging to use ids with useRef. Clean up Xcode project build phase entries (remove empty input/output paths). Apply minor code/style and config updates across source and tooling files, and update example iOS pod versions in Podfile.lock.
Switch JNI_OnLoad to call registerNatives instead of initialize. Replace PackageInfoCompat usage with Context.getPackageInfo and add explicit NameNotFoundException handling (plus a deprecation suppression) in CustomTabsPackageHelper. Add a reflection-based isHighTextContrastEnabledSafe helper in DynamicColorResolver to safely call the hidden AccessibilityManager API and fall back to false when unavailable. These changes improve JNI registration consistency and make Android package/accessibility checks more robust across API levels.
Copilot AI review requested due to automatic review settings April 22, 2026 14:34
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR modernizes the library’s public JS API (moving from a static InAppBrowser class to named exports), refactors type definitions and option/url normalization, and updates the Android/iOS implementations plus project tooling/config to improve compatibility and maintainability.

Changes:

  • Replaced the InAppBrowser static class with named exports via a new native wrapper (src/core/native.ts) and updated types to live in src/types.ts.
  • Refactored options/url validation helpers and the React hook to align with the new API surface.
  • Updated Android/iOS implementations and refreshed repo tooling/config (Biome, RN/Nitro versions, Gradle wrapper, example app configs).

Reviewed changes

Copilot reviewed 38 out of 47 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tsconfig.json Adjusted TS compiler settings (notably noEmit and rootDir).
src/utils/url.ts Replaced normalizeUrl with validateUrl and centralized scheme checks.
src/utils/options.ts Refactored option normalization to a per-key normalizer map and shared trimming helpers.
src/types.ts Introduced a central TS types/constants module for the public API surface.
src/specs/inappbrowser-nitro.nitro.ts Slimmed Nitro spec to import shared types from src/types.ts.
src/index.ts Switched to named exports from ./core/native and re-exported types/constants.
src/hooks/useInAppBrowser.ts Updated hook to call named exports and return a memoized API object.
src/core/native.ts Added lazy JSI hybrid object accessor and the new functional API (open, openAuth, etc.).
src/core/InAppBrowser.ts Removed the previous static-class wrapper.
scripts/remove-source-maps.cjs Updated Node imports to node: built-ins.
post-script.js Formatting cleanup and switched to node: built-ins.
package.json Added exports, Biome scripts, bumped dependencies, and updated Bob build targets and types paths.
nitro.json Updated Nitro autolinking schema/config layout and formatting.
ios/UIApplication+TopMost.swift Replaced manual main-thread sync with @MainActor isolation.
ios/SafariPresenter.swift Formatting plus simplifications around style mapping/availability checks.
ios/AuthSessionManager.swift Simplified to ASWebAuthenticationSession, retained presentation provider, and simplified cancel logic.
example/tsconfig.json Added ignoreDeprecations and formatting cleanup.
example/react-native.config.js Updated node: imports and reformatted config.
example/package.json Updated RN-related deps/tooling; switched linting to Biome; updated Node engine requirement.
example/metro.config.js Reformatted and switched to node: imports.
example/jest.config.js Formatting cleanup.
example/ios/InAppBrowserNitroExample/Info.plist Reorganized keys and restricted supported orientations to portrait.
example/ios/InAppBrowserNitroExample/Images.xcassets/Contents.json JSON formatting cleanup.
example/ios/InAppBrowserNitroExample/Images.xcassets/AppIcon.appiconset/Contents.json JSON formatting cleanup.
example/ios/InAppBrowserNitroExample.xcodeproj/project.pbxproj Updated build settings and flags for the example project.
example/index.js Formatting cleanup.
example/babel.config.js Updated node: imports and formatting cleanup.
example/android/gradlew.bat Modified wrapper invocation parameters.
example/android/gradlew Modified wrapper invocation parameters.
example/android/gradle/wrapper/gradle-wrapper.properties Bumped Gradle distribution URL.
example/android/gradle/wrapper/gradle-wrapper.jar Added/updated Gradle wrapper JAR.
example/android/app/build.gradle Updated comments around debuggable variants.
example/Gemfile.lock Updated Ruby gem versions (notably minitest).
example/App.tsx Updated to use named exports; improved logging and formatting/accessibility text layout.
example/.prettierrc.js Removed Prettier config (tooling migrated to Biome).
example/.eslintrc.js Removed ESLint config (tooling migrated to Biome).
biome.json Added Biome formatter/linter configuration.
android/src/main/java/com/inappbrowsernitro/browser/DynamicColorResolver.kt Improved high-contrast detection gating + safe reflection fallback.
android/src/main/java/com/inappbrowsernitro/browser/CustomTabsPackageHelper.kt Expanded package-check error handling and added deprecation suppression.
android/src/main/java/com/inappbrowsernitro/HybridInappbrowserNitro.kt Improved context handling and clarified close/closeAuth behavior.
android/src/main/cpp/cpp-adapter.cpp Switched JNI init to fbjni::initialize and explicit native registration.
android/build.gradle Added androidx.core:core dependency.
README.md Updated docs/examples for named exports and moved wrapper reference to src/core/native.ts.
.gitignore Ignored stray emitted JS/d.ts outputs under src/.
.github/FUNDING.yml Added GitHub funding configuration.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 66 to 69
private final class AuthPresentationContextProvider: NSObject, ASWebAuthenticationPresentationContextProviding {
func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
UIApplication.shared.nitroTopMostViewController?.view.window ?? UIWindow()
}
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UIApplication.nitroTopMostViewController is now @MainActor, but AuthPresentationContextProvider.presentationAnchor(for:) is not isolated to the main actor. Accessing the main-actor property from this synchronous, nonisolated method can fail strict concurrency checks. Mark AuthPresentationContextProvider (or at least presentationAnchor(for:)) as @MainActor, or use a main-actor hop that is compatible with the protocol requirements.

Copilot uses AI. Check for mistakes.
Comment on lines +56 to 68
const open = useCallback(
async (url: string, options?: InAppBrowserOptions) => {
setIsLoading(true)
setError(null)
try {
return await nativeOpen(url, options)
} catch (err) {
const next = toError(err)
setError(next)
throw next
} finally {
setIsLoading(false)
}
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hook now always calls setIsLoading(false) in finally, even if the component unmounts before nativeOpen/nativeOpenAuth resolves. This can trigger "state update on unmounted component" warnings in some React setups. Consider restoring the previous mounted-guard (e.g. useRef + cleanup) or using an abort/ignore pattern so async completions don't update state after unmount.

Copilot uses AI. Check for mistakes.
Comment thread src/utils/url.ts Outdated
Comment on lines 8 to 12
export const validateUrl = (candidate: string): string => {
const trimmed = candidate.trim()

if (!trimmed) {
throw new Error('URL must be a non-empty string.')
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

validateUrl assumes candidate is always a string and calls candidate.trim() directly. Because this is a public API boundary (called from JS), passing null/undefined/non-string values will now throw a TypeError instead of the intended, descriptive error. Consider validating typeof candidate === 'string' (or coercing safely) before trimming so callers get a consistent error message.

Copilot uses AI. Check for mistakes.
mCodex added 3 commits April 22, 2026 11:46
…nown and throw TypeError for non-string inputs - useInAppBrowser: guard setState calls behind mounted ref to avoid warnings after unmount - AuthPresentationContextProvider.presentationAnchor: mark @mainactor for strict concurrency
@mCodex mCodex merged commit 7de6fd6 into main Apr 22, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants