Skip to content

Commit

Permalink
feat!: adds support for SDK 33
Browse files Browse the repository at this point in the history
  • Loading branch information
timbru31 committed Jul 11, 2023
1 parent c8dd532 commit b104f6a
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 28 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/audit.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
on: [push, pull_request]
on:
push:
branches:
- master
pull_request:

name: Security

Expand All @@ -7,6 +11,8 @@ jobs:
name: Run a security audit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v3.5.3

- uses: actions/setup-node@v3.7.0

- run: npm audit
8 changes: 6 additions & 2 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
name: Linting

on: [push, pull_request]
on:
push:
branches:
- master
pull_request:

jobs:
build:
runs-on: macos-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v3.5.3

- name: Setup
run: brew install ktlint
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/npm-audit-fix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ jobs:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v3.5.3

- uses: ybiquitous/npm-audit-fix-action@v5
- uses: ybiquitous/npm-audit-fix-action@v5.1.0
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
14
18
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,21 @@ Additionally, when the native configuration changes, it is re-evaluated whether

Under the hood, the `Configuration.UI_MODE_NIGHT_YES`, `WebSettingsCompat.setForceDark` and `WebSettingsCompat.setForceDarkStrategy` are used. You can read more here: https://developer.android.com/guide/webapps/dark-theme

#### Attention for SDK >= 33 / Android 13

In Android 13 (SDK 33) you do not this plugin anymore as the behavior was changed [[again](https://developer.android.com/about/versions/13/behavior-changes-13). All you need to do is tweak the used theme by setting:
```xml
<preference name="AndroidPostSplashScreenTheme" value="@style/Theme.AppCompat.DayNight.NoActionBar" />
```

### Supported platforms

- **Android**

#### Prerequisites/Warnings

AndroidX and Kotlin support are required. Therefore only **cordova-android >= 9.0.0** is supported.
You need to enable Kotlin and AndroidX in your `config.xml` by setting `GradlePluginKotlinEnabled` **and** `AndroidXEnabled` to `true`.
Kotlin support is required. Due to the AndroidX support libraries used, only **cordova-android >= 11.0.0** is supported.
You need to enable Kotlin `config.xml` by setting `GradlePluginKotlinEnabled` to `true`.

### Installation

Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
"1.0.0": {
"cordova": ">= 7.0.0",
"cordova-android": ">=6.4.0"
},
"2.0.0": {
"cordova": ">= 9.0.0",
"cordova-android": ">=11.0.0"
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<engines>
<engine name="cordova" version=">=9.0.0" />
<engine name="cordova-android" version=">=9.0.0" />
<engine name="cordova-android" version=">=11.0.0" />
</engines>

<platform name="android">
Expand Down
37 changes: 20 additions & 17 deletions src/android/AndroidDarkModeSupport.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.dustplanet.cordova

import android.content.res.Configuration
import android.os.Build
import androidx.webkit.WebSettingsCompat
import androidx.webkit.WebViewFeature
import org.apache.cordova.CordovaPlugin
Expand All @@ -17,25 +18,27 @@ class AndroidDarkModeSupport : CordovaPlugin() {
}

private fun checkDarkMode() {
val nightMode: Boolean = cordova.context.resources.configuration.uiMode and
Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES
val view = (webView.engine.view as SystemWebView).settings
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.S_V2) {
val nightMode: Boolean = cordova.context.resources.configuration.uiMode and
Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES
val view = (webView.engine.view as SystemWebView).settings

if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK)) {
WebSettingsCompat.setForceDark(
view,
when {
nightMode -> WebSettingsCompat.FORCE_DARK_ON
else -> WebSettingsCompat.FORCE_DARK_OFF
},
)
}
if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK)) {
WebSettingsCompat.setForceDark(
view,
when {
nightMode -> WebSettingsCompat.FORCE_DARK_ON
else -> WebSettingsCompat.FORCE_DARK_OFF
},
)
}

if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK_STRATEGY)) {
WebSettingsCompat.setForceDarkStrategy(
view,
WebSettingsCompat.DARK_STRATEGY_WEB_THEME_DARKENING_ONLY,
)
if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK_STRATEGY)) {
WebSettingsCompat.setForceDarkStrategy(
view,
WebSettingsCompat.DARK_STRATEGY_WEB_THEME_DARKENING_ONLY,
)
}
}
}
}
2 changes: 1 addition & 1 deletion src/android/build-extras.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
dependencies {
implementation "androidx.webkit:webkit:1.4.0"
implementation "androidx.webkit:webkit:1.5.0"
}

android {
Expand Down

0 comments on commit b104f6a

Please sign in to comment.