Skip to content

manager: Refactor WebUI to Compose & Rename enableInsets to enableEdgeToEdge#3190

Merged
aviraxp merged 3 commits into
tiann:mainfrom
u9521:webui-refactor
Feb 2, 2026
Merged

manager: Refactor WebUI to Compose & Rename enableInsets to enableEdgeToEdge#3190
aviraxp merged 3 commits into
tiann:mainfrom
u9521:webui-refactor

Conversation

@u9521

@u9521 u9521 commented Feb 1, 2026

Copy link
Copy Markdown
Contributor

refactors the WebUIActivity to use Jetpack Compose, replacing the legacy View system. Javascript Interface API renaming enableInsets to enableEdgeToEdge.

Changes:

  1. Migration to Jetpack Compose
  • Replaced FrameLayout and standard WebView handling with a Composable-based architecture (WebUIScreen).
  • Replaced native WebView dialogs (onJsAlert, onJsConfirm, onJsPrompt) with Compose-based dialogs.
  • Updated Insets handling: Now uses WindowInsets.safeDrawing (includes system bars, display cutouts, and IME/keyboard).
  • Dynamic CSS Injection: Changes to insets (e.g., keyboard appearing) now dynamically update CSS variables (--safe-area-inset-*) via JS.
  • support in-app WebView history navigation via the system back gesture.
  1. API Renaming
  • Renamed: ksu.enableInsets -> ksu.enableEdgeToEdge (JS).
  • Aligns with standard Android terminology (androidx.activity.enableEdgeToEdge).
  1. Configuration Handling
  • Added configChanges handling to AndroidManifest.xml.
  • The Activity (and WebView) no longer recreates on screen rotation, multi-window mode toggling, or window resizing, preventing state loss.

u9521 added 2 commits February 1, 2026 15:23
This commit refactors the WebUI implementation to use Compose, moving away from the legacy View-based approach to improve state management and UI consistency.

Key changes:
- Migrated `WebUIActivity` to use Compose, delegating UI rendering to `WebUIScreen`.
- Implemented `WebUIScreen` to host the WebView via `AndroidView` and handle JavaScript dialogs (Alert, Confirm, Prompt) using Compose dialogs.
- Extracted WebView initialization and configuration logic into `WebViewHelper`.
- Updated `WebViewInterface` to interact with the new state holder.
- Improved window insets handling using Compose's `WindowInsets` and `snapshotFlow` to dynamically update CSS variables.
- Updated `AndroidManifest.xml` to handle configuration changes manually, preventing Activity recreation.

Signed-off-by: u9521 <63995396+u9521@users.noreply.github.com>
- Rename `enableInsets` to `enableEdgeToEdge` in both JS library and Android WebViewInterface to align with modern Android terminology.
- Update README documentation and type definitions.
- Bump js package version to 3.0.2.

Signed-off-by: u9521 <63995396+u9521@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 refactors the WebUIActivity from the legacy Android View system to Jetpack Compose, improving maintainability and modernizing the codebase. The refactor includes renaming the JavaScript API enableInsets to enableEdgeToEdge to align with standard Android terminology.

Changes:

  • Migrated WebUIActivity to Jetpack Compose with a clean separation of concerns (WebUIState for state management, WebViewHelper for setup, WebUIScreen for UI composition)
  • Replaced native WebView dialogs with Compose-based dialogs and improved insets handling with dynamic CSS injection via WindowInsets.safeDrawing
  • Renamed the JavaScript API from ksu.enableInsets to ksu.enableEdgeToEdge with corresponding updates in package.json, index.js, index.d.ts, and README.md
  • Added configChanges handling to AndroidManifest.xml to prevent activity recreation during configuration changes

Reviewed changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
WebViewInterface.kt Refactored constructor to accept WebUIState instead of individual parameters; renamed enableInsets to enableEdgeToEdge; improved code quality with var-to-val conversions
WebViewHelper.kt New file containing WebView setup logic with module validation, WebChromeClient/WebViewClient configuration, and insets handling
WebUIState.kt New file defining state management for WebUI with event handling and proper cleanup via dispose()
WebUIScreen.kt New file implementing Compose UI with AndroidView integration, dialog handling, lifecycle management, and back navigation
WebUIActivity.kt Simplified to a clean Compose implementation with MainContent composable handling state and navigation
Insets.kt Added js property for dynamic CSS variable injection when insets change
AndroidManifest.xml Added comprehensive configChanges attribute to handle configuration changes without activity recreation
js/package.json Version bump to 3.0.2
js/index.js Renamed enableInsets to enableEdgeToEdge
js/index.d.ts Updated TypeScript declarations for renamed API
js/README.md Updated documentation for enableEdgeToEdge with clearer explanation

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

Comment thread manager/app/src/main/java/me/weishu/kernelsu/ui/webui/WebUIScreen.kt Outdated
Comment thread js/package.json
Comment thread manager/app/src/main/java/me/weishu/kernelsu/ui/webui/WebUIScreen.kt Outdated
Comment thread manager/app/src/main/java/me/weishu/kernelsu/ui/webui/WebViewHelper.kt Outdated
@aviraxp

aviraxp commented Feb 1, 2026

Copy link
Copy Markdown
Collaborator

I think we need an alias for old insets api to keep combatility.

- Move WebView URL loading logic from `update` block to `factory` block to ensure consistent initialization.
- Refactor `OnLayoutChangeListener` attachment to prevent redundant triggers.
- Ensure `webView` instance is assigned to `webUIState` before adding the Javascript interface.
- Remove unused `Log` import.

Signed-off-by: u9521 <63995396+u9521@users.noreply.github.com>
@u9521

u9521 commented Feb 1, 2026

Copy link
Copy Markdown
Contributor Author

I think we need an alias for old insets api to keep combatility.

我觉得可能没有必要,一是直接调用的情况比较少,一般都是请求了css就自动 0 padding。而且是在上个release后加入的,
11天前加入的,应该没有多少适配🤔。到时候3.1.0发布把版本bump到3.1.0

@aviraxp aviraxp merged commit 9007ae6 into tiann:main Feb 2, 2026
16 checks passed
bklynali pushed a commit to bklynali/BK-KSU that referenced this pull request Feb 2, 2026
…eToEdge (tiann#3190)

refactors the WebUIActivity to use Jetpack Compose, replacing the legacy
View system. Javascript Interface API renaming enableInsets to
enableEdgeToEdge.

Changes:

1. Migration to Jetpack Compose

* Replaced `FrameLayout` and standard WebView handling with a
Composable-based architecture (`WebUIScreen`).
* Replaced native WebView dialogs (`onJsAlert`, `onJsConfirm`,
`onJsPrompt`) with Compose-based dialogs.
* Updated Insets handling: Now uses `WindowInsets.safeDrawing` (includes
system bars, display cutouts, and IME/keyboard).
* Dynamic CSS Injection: Changes to insets (e.g., keyboard appearing)
now dynamically update CSS variables (`--safe-area-inset-*`) via JS.
* support in-app WebView history navigation via the system back gesture.

2. API Renaming

* **Renamed:** `ksu.enableInsets` -> `ksu.enableEdgeToEdge` (JS).
* Aligns with standard Android terminology
(`androidx.activity.enableEdgeToEdge`).

3. Configuration Handling

* Added `configChanges` handling to `AndroidManifest.xml`.
* The Activity (and WebView) no longer recreates on screen rotation,
multi-window mode toggling, or window resizing, preventing state loss.

---------

Signed-off-by: u9521 <63995396+u9521@users.noreply.github.com>
selfmusing pushed a commit to selfmusing/USlenreK that referenced this pull request Feb 2, 2026
…eToEdge (tiann#3190)

refactors the WebUIActivity to use Jetpack Compose, replacing the legacy
View system. Javascript Interface API renaming enableInsets to
enableEdgeToEdge.

Changes:

1. Migration to Jetpack Compose

* Replaced `FrameLayout` and standard WebView handling with a
Composable-based architecture (`WebUIScreen`).
* Replaced native WebView dialogs (`onJsAlert`, `onJsConfirm`,
`onJsPrompt`) with Compose-based dialogs.
* Updated Insets handling: Now uses `WindowInsets.safeDrawing` (includes
system bars, display cutouts, and IME/keyboard).
* Dynamic CSS Injection: Changes to insets (e.g., keyboard appearing)
now dynamically update CSS variables (`--safe-area-inset-*`) via JS.
* support in-app WebView history navigation via the system back gesture.

2. API Renaming

* **Renamed:** `ksu.enableInsets` -> `ksu.enableEdgeToEdge` (JS).
* Aligns with standard Android terminology
(`androidx.activity.enableEdgeToEdge`).

3. Configuration Handling

* Added `configChanges` handling to `AndroidManifest.xml`.
* The Activity (and WebView) no longer recreates on screen rotation,
multi-window mode toggling, or window resizing, preventing state loss.

---------

Signed-off-by: u9521 <63995396+u9521@users.noreply.github.com>
selfmusing pushed a commit to selfmusing/USlenreK that referenced this pull request Feb 2, 2026
…eToEdge (tiann#3190)

refactors the WebUIActivity to use Jetpack Compose, replacing the legacy
View system. Javascript Interface API renaming enableInsets to
enableEdgeToEdge.

Changes:

1. Migration to Jetpack Compose

* Replaced `FrameLayout` and standard WebView handling with a
Composable-based architecture (`WebUIScreen`).
* Replaced native WebView dialogs (`onJsAlert`, `onJsConfirm`,
`onJsPrompt`) with Compose-based dialogs.
* Updated Insets handling: Now uses `WindowInsets.safeDrawing` (includes
system bars, display cutouts, and IME/keyboard).
* Dynamic CSS Injection: Changes to insets (e.g., keyboard appearing)
now dynamically update CSS variables (`--safe-area-inset-*`) via JS.
* support in-app WebView history navigation via the system back gesture.

2. API Renaming

* **Renamed:** `ksu.enableInsets` -> `ksu.enableEdgeToEdge` (JS).
* Aligns with standard Android terminology
(`androidx.activity.enableEdgeToEdge`).

3. Configuration Handling

* Added `configChanges` handling to `AndroidManifest.xml`.
* The Activity (and WebView) no longer recreates on screen rotation,
multi-window mode toggling, or window resizing, preventing state loss.

---------

Signed-off-by: u9521 <63995396+u9521@users.noreply.github.com>
@u9521 u9521 deleted the webui-refactor branch February 3, 2026 01:31
u9521 added a commit to u9521/KernelSU that referenced this pull request Feb 3, 2026
…eToEdge (tiann#3190)

refactors the WebUIActivity to use Jetpack Compose, replacing the legacy
View system. Javascript Interface API renaming enableInsets to
enableEdgeToEdge.

Changes:

1. Migration to Jetpack Compose

* Replaced `FrameLayout` and standard WebView handling with a
Composable-based architecture (`WebUIScreen`).
* Replaced native WebView dialogs (`onJsAlert`, `onJsConfirm`,
`onJsPrompt`) with Compose-based dialogs.
* Updated Insets handling: Now uses `WindowInsets.safeDrawing` (includes
system bars, display cutouts, and IME/keyboard).
* Dynamic CSS Injection: Changes to insets (e.g., keyboard appearing)
now dynamically update CSS variables (`--safe-area-inset-*`) via JS.
* support in-app WebView history navigation via the system back gesture.

2. API Renaming

* **Renamed:** `ksu.enableInsets` -> `ksu.enableEdgeToEdge` (JS).
* Aligns with standard Android terminology
(`androidx.activity.enableEdgeToEdge`).

3. Configuration Handling

* Added `configChanges` handling to `AndroidManifest.xml`.
* The Activity (and WebView) no longer recreates on screen rotation,
multi-window mode toggling, or window resizing, preventing state loss.

---------

Signed-off-by: u9521 <63995396+u9521@users.noreply.github.com>
KOWX712 pushed a commit to KOWX712/KernelSU that referenced this pull request Feb 3, 2026
…eToEdge (tiann#3190)

refactors the WebUIActivity to use Jetpack Compose, replacing the legacy
View system. Javascript Interface API renaming enableInsets to
enableEdgeToEdge.

Changes:

1. Migration to Jetpack Compose

* Replaced `FrameLayout` and standard WebView handling with a
Composable-based architecture (`WebUIScreen`).
* Replaced native WebView dialogs (`onJsAlert`, `onJsConfirm`,
`onJsPrompt`) with Compose-based dialogs.
* Updated Insets handling: Now uses `WindowInsets.safeDrawing` (includes
system bars, display cutouts, and IME/keyboard).
* Dynamic CSS Injection: Changes to insets (e.g., keyboard appearing)
now dynamically update CSS variables (`--safe-area-inset-*`) via JS.
* support in-app WebView history navigation via the system back gesture.

2. API Renaming

* **Renamed:** `ksu.enableInsets` -> `ksu.enableEdgeToEdge` (JS).
* Aligns with standard Android terminology
(`androidx.activity.enableEdgeToEdge`).

3. Configuration Handling

* Added `configChanges` handling to `AndroidManifest.xml`.
* The Activity (and WebView) no longer recreates on screen rotation,
multi-window mode toggling, or window resizing, preventing state loss.

---------

Signed-off-by: u9521 <63995396+u9521@users.noreply.github.com>
KOWX712 added a commit to KOWX712/ksu-webui-demo that referenced this pull request Feb 4, 2026
KOWX712 added a commit to KOWX712/kernelsu-alt that referenced this pull request Feb 4, 2026
enableInsets is renamed to enableEdgeToEdge since KernelSU 32265. Old api is kept and marked as deprecated for compatibility, there is no plan to remove it currently.

ref: tiann/KernelSU#3190
KOWX712 added a commit to KOWX712/kernelsu-alt that referenced this pull request Feb 4, 2026
enableInsets is renamed to enableEdgeToEdge since KernelSU 32265. Old api is kept and marked as deprecated for compatibility, there is no plan to remove it currently.

ref: tiann/KernelSU#3190
KOWX712 added a commit to KOWX712/kernelsu-alt that referenced this pull request Feb 4, 2026
enableInsets is renamed to enableEdgeToEdge since KernelSU 32265. Old api is kept and marked as deprecated for compatibility, there is no plan to remove it currently.

ref: tiann/KernelSU#3190
KOWX712 added a commit to KOWX712/kernelsu-alt that referenced this pull request Feb 4, 2026
enableInsets is renamed to enableEdgeToEdge since KernelSU 32265. Old api is kept and marked as deprecated for compatibility, there is no plan to remove it currently.

ref: tiann/KernelSU#3190
KOWX712 added a commit to KOWX712/kernelsu-alt that referenced this pull request Feb 4, 2026
enableInsets is renamed to enableEdgeToEdge since KernelSU 32265. Old api is kept and marked as deprecated for compatibility, there is no plan to remove it currently.

ref: tiann/KernelSU#3190
KOWX712 added a commit to KOWX712/KsuWebUIStandalone that referenced this pull request Feb 8, 2026
KOWX712 added a commit to KOWX712/KsuWebUIStandalone that referenced this pull request Feb 8, 2026
KOWX712 added a commit to KOWX712/KsuWebUIStandalone that referenced this pull request Mar 11, 2026
KOWX712 added a commit to KOWX712/KsuWebUIStandalone that referenced this pull request Mar 11, 2026
KOWX712 added a commit to KOWX712/KsuWebUIStandalone that referenced this pull request Apr 14, 2026
KOWX712 added a commit to KOWX712/FolkPatch that referenced this pull request May 29, 2026
The WebUI failed to load CSS/JS assets because the WebView was configured and loadUrl was called inside the AndroidView factory during Compose composition, which blocked the main thread and called loadUrl before the WebView had valid dimensions.
Refactor to match the KernelSU pattern:
- Create WebView and configure WebViewAssetLoader on IO dispatcher
- Build WebView fully on Main thread outside AndroidView
- Defer loadUrl until width > 0 && height > 0 via layout listener

- related:
  - tiann/KernelSU#2952
  - tiann/KernelSU#3083
  - tiann/KernelSU#3126
  - tiann/KernelSU#3190

Signed-off-by: KOWX712 <leecc0503@gmail.com>
matsuzaka-yuki pushed a commit to LyraVoid/FolkPatch that referenced this pull request May 30, 2026
#151)

The WebUI failed to load CSS/JS assets because the WebView was configured and loadUrl was called inside the AndroidView factory during Compose composition, which blocked the main thread and called loadUrl before the WebView had valid dimensions.
Refactor to match the KernelSU pattern:
- Create WebView and configure WebViewAssetLoader on IO dispatcher
- Build WebView fully on Main thread outside AndroidView
- Defer loadUrl until width > 0 && height > 0 via layout listener

- related:
  - tiann/KernelSU#2952
  - tiann/KernelSU#3083
  - tiann/KernelSU#3126
  - tiann/KernelSU#3190

Signed-off-by: KOWX712 <leecc0503@gmail.com>
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.

4 participants