├── .github
└── workflows
│ └── publish.yml
├── .gitignore
├── LICENSE
├── README.md
├── build.gradle.kts
├── gradle.properties
├── gradle
├── libs.versions.toml
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── iosApp
├── Configuration
│ └── Config.xcconfig
├── iosApp.xcodeproj
│ └── project.pbxproj
└── iosApp
│ ├── Assets.xcassets
│ ├── AccentColor.colorset
│ │ └── Contents.json
│ ├── AppIcon.appiconset
│ │ ├── Contents.json
│ │ └── app-icon-1024.png
│ └── Contents.json
│ ├── ContentView.swift
│ ├── Info.plist
│ ├── Preview Content
│ └── Preview Assets.xcassets
│ │ └── Contents.json
│ └── iOSApp.swift
├── library
├── build.gradle.kts
└── src
│ ├── androidMain
│ └── kotlin
│ │ └── com
│ │ └── final_class
│ │ └── webview_multiplatform_mobile
│ │ └── platform
│ │ └── WebViewPlatformImpl.kt
│ ├── commonMain
│ └── kotlin
│ │ └── com
│ │ └── final_class
│ │ └── webview_multiplatform_mobile
│ │ ├── platform
│ │ └── WebViewPlatformImpl.kt
│ │ └── webview
│ │ ├── WebViewPlatform.kt
│ │ ├── controller
│ │ ├── RememberWebViewController.kt
│ │ ├── WebViewController.kt
│ │ ├── WebViewControllerImpl.kt
│ │ └── state
│ │ │ └── WebViewState.kt
│ │ └── settings
│ │ ├── android
│ │ ├── AndroidSettings.kt
│ │ ├── AndroidWebViewModifier.kt
│ │ ├── AndroidWebViewModifierExtensions.kt
│ │ ├── activity_height
│ │ │ ├── ActivityHeight.kt
│ │ │ └── HeightResizeBehavior.kt
│ │ ├── android_scheme_colors
│ │ │ └── ColorSchemeParams.kt
│ │ ├── animation
│ │ │ └── AndroidAnimations.kt
│ │ ├── close_button_position
│ │ │ └── CloseButtonPosition.kt
│ │ ├── scheme
│ │ │ └── AndroidScheme.kt
│ │ └── share
│ │ │ └── ShareState.kt
│ │ └── ios
│ │ ├── IosSettings.kt
│ │ ├── IosWebViewModifier.kt
│ │ ├── IosWebViewModifierExtensions.kt
│ │ └── dismiss_button_style
│ │ └── DismissButtonStyle.kt
│ └── iosMain
│ └── kotlin
│ └── com
│ └── final_class
│ └── webview_multiplatform_mobile
│ └── platform
│ └── WebViewPlatformImpl.kt
├── sample
├── build.gradle.kts
└── src
│ ├── androidMain
│ ├── AndroidManifest.xml
│ ├── kotlin
│ │ └── com
│ │ │ └── final_class
│ │ │ └── sample_webview_multiplatform_mobile
│ │ │ └── MainActivity.kt
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ └── strings.xml
│ ├── commonMain
│ └── kotlin
│ │ └── App.kt
│ └── iosMain
│ └── kotlin
│ └── MainViewController.kt
├── settings.gradle.kts
└── static
└── logo.png
/.github/workflows/publish.yml:
--------------------------------------------------------------------------------
1 | name: Publish
2 |
3 | on:
4 | release:
5 | # We'll run this workflow when a new GitHub release is created
6 | types: [published]
7 |
8 | jobs:
9 | publish:
10 | name: Release build and publish
11 | runs-on: macos-latest
12 | steps:
13 | - name: Check out code
14 | uses: actions/checkout@v2
15 | - name: Set up JDK 17
16 | uses: actions/setup-java@v2
17 | with:
18 | distribution: adopt
19 | java-version: 17
20 |
21 | - name: Build Library
22 | run: ./gradlew library:assemble
23 |
24 | # Runs upload, and then closes & releases the repository
25 | - name: Publish to MavenCentral
26 | run: ./gradlew publishAllPublicationsToMavenCentralRepository --no-configuration-cache
27 | env:
28 | ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.ORG_GRADLE_PROJECT_mavenCentralUsername }}
29 | ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.ORG_GRADLE_PROJECT_mavenCentralPassword }}
30 | ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.ORG_GRADLE_PROJECT_signingInMemoryKey }}
31 | ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.ORG_GRADLE_PROJECT_signingInMemoryKeyId }}
32 | ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.ORG_GRADLE_PROJECT_signingInMemoryKeyPassword }}
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | .idea
4 | .DS_Store
5 | build
6 | captures
7 | .externalNativeBuild
8 | .cxx
9 | local.properties
10 | xcuserdata
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright 2024 Final Class
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | WebView Multiplatform Mobile
6 |
7 | **WebView Multiplatform Mobile** is a cross-platform library that provides a simple and convenient way to embed web content into your Android and iOS applications. Based on [CustomTabs](https://developer.android.com/reference/kotlin/androidx/browser/customtabs/package-summary) in Android and [SFSafariViewController](https://developer.apple.com/documentation/safariservices/sfsafariviewcontroller) in iOS, the library ensures safe and fast interaction with web content while maintaining the native user interface and performance.
8 |
9 | >[Here's an example of how WebView looks](https://github.com/final-class/WebView-Multiplatform-Mobile#iphone-example)
10 |
11 | ### :fire: Features:
12 | - **Cross-platform compatibility:** Support for Android and iOS to ensure a unified web content embedding experience.
13 | - **Integration with CustomTabs (Android) and SFSafariViewController (iOS):** Utilize standard components of each platform for optimal performance and security.
14 | - **Ease of use:** An intuitive API interface makes embedding web content easy and efficient for developers, with settings for each platform inspired by the Compose Modifier philosophy from Jetpack Compose.
15 |
16 | ------------
17 |
18 | ### :rocket: Setup
19 | 1) Add the dependency to the commonMain section of your build.gradle
20 | ```java
21 | implementation("io.github.final-class:webview-multiplatform-mobile:1.2.0")
22 | ```
23 | 2) Use WebView in your shared code
24 | ```kotlin
25 | val webViewController by rememberWebViewController()
26 |
27 | WebViewPlatform(webViewController = webViewController)
28 |
29 | // Open in application
30 | webViewController.open(url = "https://github.com/")
31 |
32 | // Open in external browser
33 | webViewController.openInExternalBrowser(url = "https://github.com/")
34 | ```
35 |
36 | ------------
37 |
38 | ### :gear: Settings
39 | WebView Multiplatform Mobile provides a range of customizable parameters to optimize the behavior and appearance of your embedded web components, inspired by the Compose Modifier philosophy in Jetpack Compose. Each WebView setting is akin to applying a Modifier to the embedded web component, making their usage elegant and convenient.
40 |
41 | #### Settings for Android are configured as follows:
42 | ```kotlin
43 | val webViewController by rememberWebViewController()
44 |
45 | WebViewPlatform(
46 | webViewController = webViewController,
47 | androidSettings = AndroidWebViewModifier
48 | .showTitle(true)
49 | .urlBarHidingEnabled(true)
50 | ...
51 | )
52 | ```
53 | **Description of available settings for AndroidWebViewModifier**
54 |
55 | Method | Description
56 | ------------- | -------------
57 | **showTitle** | Sets whether the title should be shown in the custom tab.
58 | **urlBarHidingEnabled** | Set whether the url bar should hide as the user scrolls down on the page.
59 | **shareState** | Sets the share state that should be applied to the custom tab.
60 | **instantAppsEnabled** | Sets whether Instant Apps is enabled for this Custom Tab.
61 | **toolbarCornerRadiusDp** | Sets the toolbar's top corner radii in dp.
62 | **activityHeight** | Sets the Custom Tab Activity's initial height in pixels and the desired resize behavior.
63 | **closeButtonPosition** | Sets the position of the close button.
64 | **startAnimations** | Sets the start animations.
65 | **exitAnimations** | Sets the exit animations.
66 | **scheme** | Sets the color scheme that should be applied to the user interface in the custom tab.
67 | **defaultColorSchemeParams** | Sets the default CustomTabColorSchemeParams. This will set a default color scheme that applies when no AndroidScheme specified for current color scheme via scheme.
68 | **darkColorSchemeParams** | Sets the dark CustomTabColorSchemeParams. This will set a dark color scheme that applies when AndroidScheme.Dark specified for current color scheme via scheme.
69 |
70 |
71 | #### Settings for iOS are configured as follows:
72 | ```kotlin
73 | val webViewController by rememberWebViewController()
74 |
75 | WebViewPlatform(
76 | webViewController = webViewController,
77 | iosSettings = IosWebViewModifier
78 | .barCollapsingEnabled(true)
79 | .entersReaderIfAvailable(true)
80 | ...
81 | )
82 | ```
83 |
84 | **Description of available settings for IosWebViewModifier**
85 |
86 | Method | Description
87 | ------------- | -------------
88 | **barCollapsingEnabled** | Enabled bar collapsing.
89 | **entersReaderIfAvailable** | A value that specifies whether Safari should enter Reader mode, if it is available.
90 | **dismissButtonStyle** | Sets dismiss button style.
91 | **preferredBarTintColor** | The color to tint the background of the navigation bar and the toolbar.
92 | **preferredControlTintColor** | The color to tint the control buttons on the navigation bar and the toolbar.
93 |
94 | ------------
95 |
96 | ### :iphone: Example
97 |
98 |  
99 |
100 | ------------
101 |
102 | ### :man_technologist: Contribution
103 | We welcome your contributions! If you have suggestions for improvement or have encountered any issues, please create an Issue or Pull Request on our GitHub repository.
104 |
105 | [](https://github.com/final-class)
106 |
--------------------------------------------------------------------------------
/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | //trick: for the same plugin versions in all sub-modules
3 | alias(libs.plugins.androidApplication) apply false
4 | alias(libs.plugins.androidLibrary) apply false
5 | alias(libs.plugins.kotlinMultiplatform) apply false
6 | alias(libs.plugins.jetbrainsCompose) apply false
7 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | #Gradle
2 | org.gradle.jvmargs=-Xmx4096M -Dfile.encoding=UTF-8 -Dkotlin.daemon.jvm.options\="-Xmx4096M"
3 | org.gradle.caching=true
4 |
5 | #Kotlin
6 | kotlin.code.style=official
7 |
8 | #Android
9 | android.useAndroidX=true
10 | android.nonTransitiveRClass=true
--------------------------------------------------------------------------------
/gradle/libs.versions.toml:
--------------------------------------------------------------------------------
1 | [versions]
2 | agp = "8.1.2"
3 | kotlin = "1.9.23"
4 | android-compileSdk = "34"
5 | android-minSdk = "21"
6 | android-targetSdk = "34"
7 | compose = "1.6.2"
8 | compose-plugin = "1.6.1"
9 | androidx-activityCompose = "1.8.0"
10 | customTabsAndroid = "1.8.0"
11 | material = "1.11.0"
12 | maven-publish = "0.28.0"
13 |
14 | [libraries]
15 | # Compose
16 | androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activityCompose" }
17 | compose-ui = { module = "androidx.compose.ui:ui", version.ref = "compose" }
18 | compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "compose" }
19 | compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview", version.ref = "compose" }
20 | compose-foundation = { module = "androidx.compose.foundation:foundation", version.ref = "compose" }
21 |
22 | # Android CustomTabs
23 | androidx-customTabs = { module = "androidx.browser:browser", version.ref = "customTabsAndroid" }
24 | material = { group = "com.google.android.material", name = "material", version.ref = "material" }
25 |
26 | [plugins]
27 | androidApplication = { id = "com.android.application", version.ref = "agp" }
28 | androidLibrary = { id = "com.android.library", version.ref = "agp" }
29 | jetbrainsCompose = { id = "org.jetbrains.compose", version.ref = "compose-plugin" }
30 | kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
31 | maven-publish = { id = "com.vanniktech.maven.publish", version.ref = "maven-publish" }
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/final-class/WebView-Multiplatform-Mobile/46d256c27771aa5f5fd954545755a5d18a2db035/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Mar 05 00:06:58 MSK 2024
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | #distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
5 | #distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
7 | zipStoreBase=GRADLE_USER_HOME
8 | zipStorePath=wrapper/dists
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 |
86 | # Determine the Java command to use to start the JVM.
87 | if [ -n "$JAVA_HOME" ] ; then
88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
89 | # IBM's JDK on AIX uses strange locations for the executables
90 | JAVACMD="$JAVA_HOME/jre/sh/java"
91 | else
92 | JAVACMD="$JAVA_HOME/bin/java"
93 | fi
94 | if [ ! -x "$JAVACMD" ] ; then
95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
96 |
97 | Please set the JAVA_HOME variable in your environment to match the
98 | location of your Java installation."
99 | fi
100 | else
101 | JAVACMD="java"
102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
103 |
104 | Please set the JAVA_HOME variable in your environment to match the
105 | location of your Java installation."
106 | fi
107 |
108 | # Increase the maximum file descriptors if we can.
109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
110 | MAX_FD_LIMIT=`ulimit -H -n`
111 | if [ $? -eq 0 ] ; then
112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
113 | MAX_FD="$MAX_FD_LIMIT"
114 | fi
115 | ulimit -n $MAX_FD
116 | if [ $? -ne 0 ] ; then
117 | warn "Could not set maximum file descriptor limit: $MAX_FD"
118 | fi
119 | else
120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
121 | fi
122 | fi
123 |
124 | # For Darwin, add options to specify how the application appears in the dock
125 | if $darwin; then
126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
127 | fi
128 |
129 | # For Cygwin or MSYS, switch paths to Windows format before running java
130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133 |
134 | JAVACMD=`cygpath --unix "$JAVACMD"`
135 |
136 | # We build the pattern for arguments to be converted via cygpath
137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
138 | SEP=""
139 | for dir in $ROOTDIRSRAW ; do
140 | ROOTDIRS="$ROOTDIRS$SEP$dir"
141 | SEP="|"
142 | done
143 | OURCYGPATTERN="(^($ROOTDIRS))"
144 | # Add a user-defined pattern to the cygpath arguments
145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
147 | fi
148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
149 | i=0
150 | for arg in "$@" ; do
151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
153 |
154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
156 | else
157 | eval `echo args$i`="\"$arg\""
158 | fi
159 | i=`expr $i + 1`
160 | done
161 | case $i in
162 | 0) set -- ;;
163 | 1) set -- "$args0" ;;
164 | 2) set -- "$args0" "$args1" ;;
165 | 3) set -- "$args0" "$args1" "$args2" ;;
166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
172 | esac
173 | fi
174 |
175 | # Escape application args
176 | save () {
177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
178 | echo " "
179 | }
180 | APP_ARGS=`save "$@"`
181 |
182 | # Collect all arguments for the java command, following the shell quoting and substitution rules
183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
184 |
185 | exec "$JAVACMD" "$@"
186 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/iosApp/Configuration/Config.xcconfig:
--------------------------------------------------------------------------------
1 | TEAM_ID=
2 | BUNDLE_ID=com.final_class.sample_webview_multiplatform_mobile.SampleWebViewMultiplatformMobile
3 | APP_NAME=Sample WebView Multiplatform Mobile
--------------------------------------------------------------------------------
/iosApp/iosApp.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 54;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | 058557BB273AAA24004C7B11 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 058557BA273AAA24004C7B11 /* Assets.xcassets */; };
11 | 058557D9273AAEEB004C7B11 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 058557D8273AAEEB004C7B11 /* Preview Assets.xcassets */; };
12 | 2152FB042600AC8F00CF470E /* iOSApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2152FB032600AC8F00CF470E /* iOSApp.swift */; };
13 | 7555FF83242A565900829871 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7555FF82242A565900829871 /* ContentView.swift */; };
14 | /* End PBXBuildFile section */
15 |
16 | /* Begin PBXFileReference section */
17 | 058557BA273AAA24004C7B11 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; };
18 | 058557D8273AAEEB004C7B11 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; };
19 | 2152FB032600AC8F00CF470E /* iOSApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = iOSApp.swift; sourceTree = ""; };
20 | 7555FF7B242A565900829871 /* Sample WebView Multiplatform Mobile.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Sample WebView Multiplatform Mobile.app"; sourceTree = BUILT_PRODUCTS_DIR; };
21 | 7555FF82242A565900829871 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; };
22 | 7555FF8C242A565B00829871 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
23 | AB3632DC29227652001CCB65 /* Config.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Config.xcconfig; sourceTree = ""; };
24 | /* End PBXFileReference section */
25 |
26 | /* Begin PBXFrameworksBuildPhase section */
27 | B92378962B6B1156000C7307 /* Frameworks */ = {
28 | isa = PBXFrameworksBuildPhase;
29 | buildActionMask = 2147483647;
30 | files = (
31 | );
32 | runOnlyForDeploymentPostprocessing = 0;
33 | };
34 | /* End PBXFrameworksBuildPhase section */
35 |
36 | /* Begin PBXGroup section */
37 | 058557D7273AAEEB004C7B11 /* Preview Content */ = {
38 | isa = PBXGroup;
39 | children = (
40 | 058557D8273AAEEB004C7B11 /* Preview Assets.xcassets */,
41 | );
42 | path = "Preview Content";
43 | sourceTree = "";
44 | };
45 | 42799AB246E5F90AF97AA0EF /* Frameworks */ = {
46 | isa = PBXGroup;
47 | children = (
48 | );
49 | name = Frameworks;
50 | sourceTree = "";
51 | };
52 | 7555FF72242A565900829871 = {
53 | isa = PBXGroup;
54 | children = (
55 | AB1DB47929225F7C00F7AF9C /* Configuration */,
56 | 7555FF7D242A565900829871 /* iosApp */,
57 | 7555FF7C242A565900829871 /* Products */,
58 | 42799AB246E5F90AF97AA0EF /* Frameworks */,
59 | );
60 | sourceTree = "";
61 | };
62 | 7555FF7C242A565900829871 /* Products */ = {
63 | isa = PBXGroup;
64 | children = (
65 | 7555FF7B242A565900829871 /* Sample WebView Multiplatform Mobile.app */,
66 | );
67 | name = Products;
68 | sourceTree = "";
69 | };
70 | 7555FF7D242A565900829871 /* iosApp */ = {
71 | isa = PBXGroup;
72 | children = (
73 | 058557BA273AAA24004C7B11 /* Assets.xcassets */,
74 | 7555FF82242A565900829871 /* ContentView.swift */,
75 | 7555FF8C242A565B00829871 /* Info.plist */,
76 | 2152FB032600AC8F00CF470E /* iOSApp.swift */,
77 | 058557D7273AAEEB004C7B11 /* Preview Content */,
78 | );
79 | path = iosApp;
80 | sourceTree = "";
81 | };
82 | AB1DB47929225F7C00F7AF9C /* Configuration */ = {
83 | isa = PBXGroup;
84 | children = (
85 | AB3632DC29227652001CCB65 /* Config.xcconfig */,
86 | );
87 | path = Configuration;
88 | sourceTree = "";
89 | };
90 | /* End PBXGroup section */
91 |
92 | /* Begin PBXNativeTarget section */
93 | 7555FF7A242A565900829871 /* iosApp */ = {
94 | isa = PBXNativeTarget;
95 | buildConfigurationList = 7555FFA5242A565B00829871 /* Build configuration list for PBXNativeTarget "iosApp" */;
96 | buildPhases = (
97 | F36B1CEB2AD83DDC00CB74D5 /* Compile Kotlin Framework */,
98 | 7555FF77242A565900829871 /* Sources */,
99 | B92378962B6B1156000C7307 /* Frameworks */,
100 | 7555FF79242A565900829871 /* Resources */,
101 | );
102 | buildRules = (
103 | );
104 | dependencies = (
105 | );
106 | name = iosApp;
107 | packageProductDependencies = (
108 | );
109 | productName = iosApp;
110 | productReference = 7555FF7B242A565900829871 /* Sample WebView Multiplatform Mobile.app */;
111 | productType = "com.apple.product-type.application";
112 | };
113 | /* End PBXNativeTarget section */
114 |
115 | /* Begin PBXProject section */
116 | 7555FF73242A565900829871 /* Project object */ = {
117 | isa = PBXProject;
118 | attributes = {
119 | LastSwiftUpdateCheck = 1130;
120 | LastUpgradeCheck = 1130;
121 | ORGANIZATIONNAME = orgName;
122 | TargetAttributes = {
123 | 7555FF7A242A565900829871 = {
124 | CreatedOnToolsVersion = 11.3.1;
125 | };
126 | };
127 | };
128 | buildConfigurationList = 7555FF76242A565900829871 /* Build configuration list for PBXProject "iosApp" */;
129 | compatibilityVersion = "Xcode 12.0";
130 | developmentRegion = en;
131 | hasScannedForEncodings = 0;
132 | knownRegions = (
133 | en,
134 | Base,
135 | );
136 | mainGroup = 7555FF72242A565900829871;
137 | packageReferences = (
138 | );
139 | productRefGroup = 7555FF7C242A565900829871 /* Products */;
140 | projectDirPath = "";
141 | projectRoot = "";
142 | targets = (
143 | 7555FF7A242A565900829871 /* iosApp */,
144 | );
145 | };
146 | /* End PBXProject section */
147 |
148 | /* Begin PBXResourcesBuildPhase section */
149 | 7555FF79242A565900829871 /* Resources */ = {
150 | isa = PBXResourcesBuildPhase;
151 | buildActionMask = 2147483647;
152 | files = (
153 | 058557D9273AAEEB004C7B11 /* Preview Assets.xcassets in Resources */,
154 | 058557BB273AAA24004C7B11 /* Assets.xcassets in Resources */,
155 | );
156 | runOnlyForDeploymentPostprocessing = 0;
157 | };
158 | /* End PBXResourcesBuildPhase section */
159 |
160 | /* Begin PBXShellScriptBuildPhase section */
161 | F36B1CEB2AD83DDC00CB74D5 /* Compile Kotlin Framework */ = {
162 | isa = PBXShellScriptBuildPhase;
163 | buildActionMask = 2147483647;
164 | files = (
165 | );
166 | inputFileListPaths = (
167 | );
168 | inputPaths = (
169 | );
170 | name = "Compile Kotlin Framework";
171 | outputFileListPaths = (
172 | );
173 | outputPaths = (
174 | );
175 | runOnlyForDeploymentPostprocessing = 0;
176 | shellPath = /bin/sh;
177 | shellScript = "if [ \"YES\" = \"$OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED\" ]; then\n echo \"Skipping Gradle build task invocation due to OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED environment variable set to \\\"YES\\\"\"\n exit 0\nfi\ncd \"$SRCROOT/..\"\n./gradlew :sample:embedAndSignAppleFrameworkForXcode\n";
178 | };
179 | /* End PBXShellScriptBuildPhase section */
180 |
181 | /* Begin PBXSourcesBuildPhase section */
182 | 7555FF77242A565900829871 /* Sources */ = {
183 | isa = PBXSourcesBuildPhase;
184 | buildActionMask = 2147483647;
185 | files = (
186 | 2152FB042600AC8F00CF470E /* iOSApp.swift in Sources */,
187 | 7555FF83242A565900829871 /* ContentView.swift in Sources */,
188 | );
189 | runOnlyForDeploymentPostprocessing = 0;
190 | };
191 | /* End PBXSourcesBuildPhase section */
192 |
193 | /* Begin XCBuildConfiguration section */
194 | 7555FFA3242A565B00829871 /* Debug */ = {
195 | isa = XCBuildConfiguration;
196 | baseConfigurationReference = AB3632DC29227652001CCB65 /* Config.xcconfig */;
197 | buildSettings = {
198 | ALWAYS_SEARCH_USER_PATHS = NO;
199 | CLANG_ANALYZER_NONNULL = YES;
200 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
201 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
202 | CLANG_CXX_LIBRARY = "libc++";
203 | CLANG_ENABLE_MODULES = YES;
204 | CLANG_ENABLE_OBJC_ARC = YES;
205 | CLANG_ENABLE_OBJC_WEAK = YES;
206 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
207 | CLANG_WARN_BOOL_CONVERSION = YES;
208 | CLANG_WARN_COMMA = YES;
209 | CLANG_WARN_CONSTANT_CONVERSION = YES;
210 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
211 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
212 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
213 | CLANG_WARN_EMPTY_BODY = YES;
214 | CLANG_WARN_ENUM_CONVERSION = YES;
215 | CLANG_WARN_INFINITE_RECURSION = YES;
216 | CLANG_WARN_INT_CONVERSION = YES;
217 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
218 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
219 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
220 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
221 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
222 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
223 | CLANG_WARN_STRICT_PROTOTYPES = YES;
224 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
225 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
226 | CLANG_WARN_UNREACHABLE_CODE = YES;
227 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
228 | COPY_PHASE_STRIP = NO;
229 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
230 | ENABLE_STRICT_OBJC_MSGSEND = YES;
231 | ENABLE_TESTABILITY = YES;
232 | GCC_C_LANGUAGE_STANDARD = gnu11;
233 | GCC_DYNAMIC_NO_PIC = NO;
234 | GCC_NO_COMMON_BLOCKS = YES;
235 | GCC_OPTIMIZATION_LEVEL = 0;
236 | GCC_PREPROCESSOR_DEFINITIONS = (
237 | "DEBUG=1",
238 | "$(inherited)",
239 | );
240 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
241 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
242 | GCC_WARN_UNDECLARED_SELECTOR = YES;
243 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
244 | GCC_WARN_UNUSED_FUNCTION = YES;
245 | GCC_WARN_UNUSED_VARIABLE = YES;
246 | IPHONEOS_DEPLOYMENT_TARGET = 15.3;
247 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
248 | MTL_FAST_MATH = YES;
249 | ONLY_ACTIVE_ARCH = YES;
250 | SDKROOT = iphoneos;
251 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
252 | SWIFT_OPTIMIZATION_LEVEL = "-Onone";
253 | };
254 | name = Debug;
255 | };
256 | 7555FFA4242A565B00829871 /* Release */ = {
257 | isa = XCBuildConfiguration;
258 | baseConfigurationReference = AB3632DC29227652001CCB65 /* Config.xcconfig */;
259 | buildSettings = {
260 | ALWAYS_SEARCH_USER_PATHS = NO;
261 | CLANG_ANALYZER_NONNULL = YES;
262 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
263 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
264 | CLANG_CXX_LIBRARY = "libc++";
265 | CLANG_ENABLE_MODULES = YES;
266 | CLANG_ENABLE_OBJC_ARC = YES;
267 | CLANG_ENABLE_OBJC_WEAK = YES;
268 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
269 | CLANG_WARN_BOOL_CONVERSION = YES;
270 | CLANG_WARN_COMMA = YES;
271 | CLANG_WARN_CONSTANT_CONVERSION = YES;
272 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
273 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
274 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
275 | CLANG_WARN_EMPTY_BODY = YES;
276 | CLANG_WARN_ENUM_CONVERSION = YES;
277 | CLANG_WARN_INFINITE_RECURSION = YES;
278 | CLANG_WARN_INT_CONVERSION = YES;
279 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
280 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
281 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
282 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
283 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
284 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
285 | CLANG_WARN_STRICT_PROTOTYPES = YES;
286 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
287 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
288 | CLANG_WARN_UNREACHABLE_CODE = YES;
289 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
290 | COPY_PHASE_STRIP = NO;
291 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
292 | ENABLE_NS_ASSERTIONS = NO;
293 | ENABLE_STRICT_OBJC_MSGSEND = YES;
294 | GCC_C_LANGUAGE_STANDARD = gnu11;
295 | GCC_NO_COMMON_BLOCKS = YES;
296 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
297 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
298 | GCC_WARN_UNDECLARED_SELECTOR = YES;
299 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
300 | GCC_WARN_UNUSED_FUNCTION = YES;
301 | GCC_WARN_UNUSED_VARIABLE = YES;
302 | IPHONEOS_DEPLOYMENT_TARGET = 15.3;
303 | MTL_ENABLE_DEBUG_INFO = NO;
304 | MTL_FAST_MATH = YES;
305 | SDKROOT = iphoneos;
306 | SWIFT_COMPILATION_MODE = wholemodule;
307 | SWIFT_OPTIMIZATION_LEVEL = "-O";
308 | VALIDATE_PRODUCT = YES;
309 | };
310 | name = Release;
311 | };
312 | 7555FFA6242A565B00829871 /* Debug */ = {
313 | isa = XCBuildConfiguration;
314 | buildSettings = {
315 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
316 | CODE_SIGN_IDENTITY = "Apple Development";
317 | CODE_SIGN_STYLE = Automatic;
318 | DEVELOPMENT_ASSET_PATHS = "\"iosApp/Preview Content\"";
319 | DEVELOPMENT_TEAM = "${TEAM_ID}";
320 | ENABLE_PREVIEWS = YES;
321 | FRAMEWORK_SEARCH_PATHS = (
322 | "$(SRCROOT)/../shared/build/xcode-frameworks/$(CONFIGURATION)/$(SDK_NAME)\n$(SRCROOT)/../sample/build/xcode-frameworks/$(CONFIGURATION)/$(SDK_NAME)",
323 | );
324 | INFOPLIST_FILE = iosApp/Info.plist;
325 | IPHONEOS_DEPLOYMENT_TARGET = 15.3;
326 | LD_RUNPATH_SEARCH_PATHS = (
327 | "$(inherited)",
328 | "@executable_path/Frameworks",
329 | );
330 | OTHER_LDFLAGS = (
331 | "$(inherited)",
332 | "-framework",
333 | sample,
334 | );
335 | PRODUCT_BUNDLE_IDENTIFIER = "${BUNDLE_ID}${TEAM_ID}";
336 | PRODUCT_NAME = "${APP_NAME}";
337 | PROVISIONING_PROFILE_SPECIFIER = "";
338 | SWIFT_VERSION = 5.0;
339 | TARGETED_DEVICE_FAMILY = "1,2";
340 | };
341 | name = Debug;
342 | };
343 | 7555FFA7242A565B00829871 /* Release */ = {
344 | isa = XCBuildConfiguration;
345 | buildSettings = {
346 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
347 | CODE_SIGN_IDENTITY = "Apple Development";
348 | CODE_SIGN_STYLE = Automatic;
349 | DEVELOPMENT_ASSET_PATHS = "\"iosApp/Preview Content\"";
350 | DEVELOPMENT_TEAM = "${TEAM_ID}";
351 | ENABLE_PREVIEWS = YES;
352 | FRAMEWORK_SEARCH_PATHS = (
353 | "$(SRCROOT)/../shared/build/xcode-frameworks/$(CONFIGURATION)/$(SDK_NAME)\n$(SRCROOT)/../sample/build/xcode-frameworks/$(CONFIGURATION)/$(SDK_NAME)",
354 | );
355 | INFOPLIST_FILE = iosApp/Info.plist;
356 | IPHONEOS_DEPLOYMENT_TARGET = 15.3;
357 | LD_RUNPATH_SEARCH_PATHS = (
358 | "$(inherited)",
359 | "@executable_path/Frameworks",
360 | );
361 | OTHER_LDFLAGS = (
362 | "$(inherited)",
363 | "-framework",
364 | sample,
365 | );
366 | PRODUCT_BUNDLE_IDENTIFIER = "${BUNDLE_ID}${TEAM_ID}";
367 | PRODUCT_NAME = "${APP_NAME}";
368 | PROVISIONING_PROFILE_SPECIFIER = "";
369 | SWIFT_VERSION = 5.0;
370 | TARGETED_DEVICE_FAMILY = "1,2";
371 | };
372 | name = Release;
373 | };
374 | /* End XCBuildConfiguration section */
375 |
376 | /* Begin XCConfigurationList section */
377 | 7555FF76242A565900829871 /* Build configuration list for PBXProject "iosApp" */ = {
378 | isa = XCConfigurationList;
379 | buildConfigurations = (
380 | 7555FFA3242A565B00829871 /* Debug */,
381 | 7555FFA4242A565B00829871 /* Release */,
382 | );
383 | defaultConfigurationIsVisible = 0;
384 | defaultConfigurationName = Release;
385 | };
386 | 7555FFA5242A565B00829871 /* Build configuration list for PBXNativeTarget "iosApp" */ = {
387 | isa = XCConfigurationList;
388 | buildConfigurations = (
389 | 7555FFA6242A565B00829871 /* Debug */,
390 | 7555FFA7242A565B00829871 /* Release */,
391 | );
392 | defaultConfigurationIsVisible = 0;
393 | defaultConfigurationName = Release;
394 | };
395 | /* End XCConfigurationList section */
396 | };
397 | rootObject = 7555FF73242A565900829871 /* Project object */;
398 | }
399 |
--------------------------------------------------------------------------------
/iosApp/iosApp/Assets.xcassets/AccentColor.colorset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "colors" : [
3 | {
4 | "idiom" : "universal"
5 | }
6 | ],
7 | "info" : {
8 | "author" : "xcode",
9 | "version" : 1
10 | }
11 | }
--------------------------------------------------------------------------------
/iosApp/iosApp/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "filename" : "app-icon-1024.png",
5 | "idiom" : "universal",
6 | "platform" : "ios",
7 | "size" : "1024x1024"
8 | }
9 | ],
10 | "info" : {
11 | "author" : "xcode",
12 | "version" : 1
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/iosApp/iosApp/Assets.xcassets/AppIcon.appiconset/app-icon-1024.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/final-class/WebView-Multiplatform-Mobile/46d256c27771aa5f5fd954545755a5d18a2db035/iosApp/iosApp/Assets.xcassets/AppIcon.appiconset/app-icon-1024.png
--------------------------------------------------------------------------------
/iosApp/iosApp/Assets.xcassets/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "info" : {
3 | "author" : "xcode",
4 | "version" : 1
5 | }
6 | }
--------------------------------------------------------------------------------
/iosApp/iosApp/ContentView.swift:
--------------------------------------------------------------------------------
1 | import UIKit
2 | import SwiftUI
3 | import Sample
4 |
5 | struct ComposeView: UIViewControllerRepresentable {
6 | func makeUIViewController(context: Context) -> UIViewController {
7 | MainViewControllerKt.MainViewController()
8 | }
9 |
10 | func updateUIViewController(_ uiViewController: UIViewController, context: Context) {}
11 | }
12 |
13 | struct ContentView: View {
14 | var body: some View {
15 | ComposeView()
16 | .ignoresSafeArea(.keyboard) // Compose has own keyboard handler
17 | }
18 | }
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/iosApp/iosApp/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE)
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleVersion
20 | 1
21 | LSRequiresIPhoneOS
22 |
23 | CADisableMinimumFrameDurationOnPhone
24 |
25 | UIApplicationSceneManifest
26 |
27 | UIApplicationSupportsMultipleScenes
28 |
29 |
30 | UILaunchScreen
31 |
32 | UIRequiredDeviceCapabilities
33 |
34 | armv7
35 |
36 | UISupportedInterfaceOrientations
37 |
38 | UIInterfaceOrientationPortrait
39 | UIInterfaceOrientationLandscapeLeft
40 | UIInterfaceOrientationLandscapeRight
41 |
42 | UISupportedInterfaceOrientations~ipad
43 |
44 | UIInterfaceOrientationPortrait
45 | UIInterfaceOrientationPortraitUpsideDown
46 | UIInterfaceOrientationLandscapeLeft
47 | UIInterfaceOrientationLandscapeRight
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/iosApp/iosApp/Preview Content/Preview Assets.xcassets/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "info" : {
3 | "author" : "xcode",
4 | "version" : 1
5 | }
6 | }
--------------------------------------------------------------------------------
/iosApp/iosApp/iOSApp.swift:
--------------------------------------------------------------------------------
1 | import SwiftUI
2 |
3 | @main
4 | struct iOSApp: App {
5 | var body: some Scene {
6 | WindowGroup {
7 | ContentView()
8 | }
9 | }
10 | }
--------------------------------------------------------------------------------
/library/build.gradle.kts:
--------------------------------------------------------------------------------
1 | import com.vanniktech.maven.publish.SonatypeHost
2 |
3 | plugins {
4 | alias(libs.plugins.kotlinMultiplatform)
5 | alias(libs.plugins.androidLibrary)
6 | alias(libs.plugins.jetbrainsCompose)
7 | alias(libs.plugins.maven.publish)
8 | }
9 |
10 | kotlin {
11 | androidTarget {
12 | compilations.all {
13 | kotlinOptions {
14 | jvmTarget = "1.8"
15 | }
16 | }
17 | }
18 |
19 | listOf(
20 | iosX64(),
21 | iosArm64(),
22 | iosSimulatorArm64()
23 | ).forEach {
24 | it.binaries.framework {
25 | baseName = "shared"
26 | isStatic = true
27 | }
28 | }
29 |
30 | sourceSets {
31 | commonMain.dependencies {
32 | /** Compose **/
33 | implementation(compose.foundation)
34 | }
35 |
36 | androidMain.dependencies {
37 | /** Compose **/
38 | implementation(libs.androidx.activity.compose)
39 |
40 | /** CustomTabs **/
41 | implementation(libs.androidx.customTabs)
42 | }
43 | }
44 | }
45 |
46 | android {
47 | namespace = "com.final_class.webview_multiplatform_mobile"
48 | compileSdk = libs.versions.android.compileSdk.get().toInt()
49 | defaultConfig {
50 | minSdk = libs.versions.android.minSdk.get().toInt()
51 | targetSdk = libs.versions.android.targetSdk.get().toInt()
52 | }
53 | }
54 |
55 | mavenPublishing {
56 | val version = "1.2.0"
57 | val groupId = "io.github.final-class"
58 | val artifact = "webview-multiplatform-mobile"
59 |
60 | coordinates(groupId, artifact, version)
61 |
62 | pom {
63 | name.set("WebView-Multiplatform-Mobile")
64 | description.set("WebView library for Kotlin Mobile Multiplatform (Android/iOS)")
65 | url.set("https://github.com/final-class/WebView-Multiplatform-Mobile")
66 |
67 | licenses {
68 | license {
69 | name.set("Library Licence")
70 | url.set("https://github.com/final-class/WebView-Multiplatform-Mobile/blob/main/LICENSE")
71 | }
72 | }
73 |
74 | developers {
75 | developer {
76 | id.set("final-class")
77 | name.set("Dmitry Aleksandrovich")
78 | url.set("https://github.com/final-class")
79 | }
80 | }
81 |
82 | scm {
83 | connection.set("scm:git:github.com/final-class/WebView-Multiplatform-Mobile.git")
84 | developerConnection.set("scm:git:ssh://github.com/final-class/WebView-Multiplatform-Mobile.git")
85 | url.set("https://github.com/final-class/WebView-Multiplatform-Mobile/tree/main")
86 | }
87 | }
88 |
89 | publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL)
90 | signAllPublications()
91 | }
--------------------------------------------------------------------------------
/library/src/androidMain/kotlin/com/final_class/webview_multiplatform_mobile/platform/WebViewPlatformImpl.kt:
--------------------------------------------------------------------------------
1 | package com.final_class.webview_multiplatform_mobile.platform
2 |
3 | import android.content.Context
4 | import android.content.Intent
5 | import android.net.Uri
6 | import androidx.browser.customtabs.CustomTabColorSchemeParams
7 | import androidx.browser.customtabs.CustomTabsIntent
8 | import androidx.browser.customtabs.CustomTabsIntent.ACTIVITY_HEIGHT_ADJUSTABLE
9 | import androidx.browser.customtabs.CustomTabsIntent.ACTIVITY_HEIGHT_DEFAULT
10 | import androidx.browser.customtabs.CustomTabsIntent.ACTIVITY_HEIGHT_FIXED
11 | import androidx.browser.customtabs.CustomTabsIntent.CLOSE_BUTTON_POSITION_DEFAULT
12 | import androidx.browser.customtabs.CustomTabsIntent.CLOSE_BUTTON_POSITION_END
13 | import androidx.browser.customtabs.CustomTabsIntent.CLOSE_BUTTON_POSITION_START
14 | import androidx.compose.runtime.Composable
15 | import androidx.compose.ui.graphics.toArgb
16 | import androidx.compose.ui.platform.LocalContext
17 | import com.final_class.webview_multiplatform_mobile.webview.settings.android.AndroidSettings
18 | import com.final_class.webview_multiplatform_mobile.webview.settings.android.activity_height.ActivityHeight
19 | import com.final_class.webview_multiplatform_mobile.webview.settings.android.activity_height.HeightResizeBehavior
20 | import com.final_class.webview_multiplatform_mobile.webview.settings.android.android_scheme_colors.ColorSchemeParams
21 | import com.final_class.webview_multiplatform_mobile.webview.settings.android.close_button_position.CloseButtonPosition
22 | import com.final_class.webview_multiplatform_mobile.webview.settings.android.scheme.AndroidScheme
23 | import com.final_class.webview_multiplatform_mobile.webview.settings.android.share.ShareState
24 | import com.final_class.webview_multiplatform_mobile.webview.settings.ios.IosSettings
25 |
26 | @Composable
27 | internal actual fun WebViewPlatformImpl(
28 | url: String,
29 | openInExternalBrowser: Boolean,
30 | androidSettings: AndroidSettings,
31 | iosSettings: IosSettings,
32 | ) {
33 | val context = LocalContext.current
34 |
35 | val customTabsIntent = createCustomTabs(
36 | context = context,
37 | androidSettings = androidSettings,
38 | openInExternalBrowser = openInExternalBrowser
39 | )
40 |
41 | customTabsIntent.launchUrl(context, Uri.parse(url))
42 | }
43 |
44 | private fun createCustomTabs(context: Context, androidSettings: AndroidSettings, openInExternalBrowser: Boolean): CustomTabsIntent {
45 | val customTabsBuilder = CustomTabsIntent.Builder()
46 |
47 | androidSettings.showTitle?.let { customTabsBuilder.setShowTitle(it) }
48 | androidSettings.urlBarHidingEnabled?.let { customTabsBuilder.setUrlBarHidingEnabled(it) }
49 | androidSettings.shareState?.let { customTabsBuilder.setShareState(it) }
50 | androidSettings.instantAppsEnabled?.let { customTabsBuilder.setInstantAppsEnabled(it) }
51 | androidSettings.toolbarCornerRadiusDp?.let { customTabsBuilder.setToolbarCornerRadiusDp(it) }
52 | androidSettings.activityHeight?.let { customTabsBuilder.setInitialActivityHeightPx(it) }
53 | androidSettings.closeButtonPosition?.let { customTabsBuilder.setCloseButtonIcon(it) }
54 | androidSettings.startAnimation?.let { customTabsBuilder.setStartAnimations(context, it.enterResId, it.exitResId) }
55 | androidSettings.exitAnimation?.let { customTabsBuilder.setExitAnimations(context, it.enterResId, it.exitResId) }
56 | androidSettings.scheme?.let { customTabsBuilder.setColorScheme(scheme = it) }
57 | androidSettings.defaultColorSchemeParams?.let { customTabsBuilder.setDefaultColorSchemeParams(it) }
58 | androidSettings.darkColorSchemeParams?.let { customTabsBuilder.setDarkColorSchemeParams(it) }
59 |
60 | return customTabsBuilder.build().apply {
61 | if (openInExternalBrowser) intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
62 | }
63 | }
64 |
65 | private fun CustomTabsIntent.Builder.setShareState(shareState: ShareState) {
66 | when (shareState) {
67 | ShareState.SHARE_STATE_DEFAULT -> this.setShareState(CustomTabsIntent.SHARE_STATE_DEFAULT)
68 | ShareState.SHARE_STATE_ON -> this.setShareState(CustomTabsIntent.SHARE_STATE_ON)
69 | ShareState.SHARE_STATE_OFF -> this.setShareState(CustomTabsIntent.SHARE_STATE_OFF)
70 | }
71 | }
72 |
73 | private fun CustomTabsIntent.Builder.setInitialActivityHeightPx(activityHeight: ActivityHeight) {
74 | val heightResizeBehavior = when (activityHeight.heightResizeBehavior) {
75 | HeightResizeBehavior.ACTIVITY_HEIGHT_DEFAULT -> ACTIVITY_HEIGHT_DEFAULT
76 | HeightResizeBehavior.ACTIVITY_HEIGHT_ADJUSTABLE -> ACTIVITY_HEIGHT_ADJUSTABLE
77 | HeightResizeBehavior.ACTIVITY_HEIGHT_FIXED -> ACTIVITY_HEIGHT_FIXED
78 | else -> null
79 | }
80 |
81 | if (heightResizeBehavior == null) {
82 | this.setInitialActivityHeightPx(activityHeight.initialHeightPx)
83 | } else {
84 | this.setInitialActivityHeightPx(activityHeight.initialHeightPx, heightResizeBehavior)
85 | }
86 | }
87 |
88 | private fun CustomTabsIntent.Builder.setCloseButtonIcon(closeButtonPosition: CloseButtonPosition) {
89 | val closeButtonPosition = when (closeButtonPosition) {
90 | CloseButtonPosition.DEFAULT -> CLOSE_BUTTON_POSITION_DEFAULT
91 | CloseButtonPosition.START -> CLOSE_BUTTON_POSITION_START
92 | CloseButtonPosition.END -> CLOSE_BUTTON_POSITION_END
93 | }
94 |
95 | this.setCloseButtonPosition(closeButtonPosition)
96 | }
97 |
98 | private fun CustomTabsIntent.Builder.setColorScheme(scheme: AndroidScheme) {
99 | when (scheme) {
100 | AndroidScheme.System -> this.setColorScheme(CustomTabsIntent.COLOR_SCHEME_SYSTEM)
101 | AndroidScheme.Light -> this.setColorScheme(CustomTabsIntent.COLOR_SCHEME_LIGHT)
102 | AndroidScheme.Dark -> this.setColorScheme(CustomTabsIntent.COLOR_SCHEME_DARK)
103 | }
104 | }
105 |
106 | private fun CustomTabsIntent.Builder.setDefaultColorSchemeParams(colorSchemeParams: ColorSchemeParams) {
107 | val customTabColorSchemeParams = CustomTabColorSchemeParams.Builder()
108 |
109 | colorSchemeParams.toolbarColor?.let { customTabColorSchemeParams.setToolbarColor(it.toArgb()) }
110 | colorSchemeParams.secondaryToolbarColor?.let { customTabColorSchemeParams.setSecondaryToolbarColor(it.toArgb()) }
111 | colorSchemeParams.navigationBarColor?.let { customTabColorSchemeParams.setNavigationBarColor(it.toArgb()) }
112 | colorSchemeParams.navigationBarDividerColor?.let { customTabColorSchemeParams.setNavigationBarDividerColor(it.toArgb()) }
113 |
114 | this.setDefaultColorSchemeParams(customTabColorSchemeParams.build())
115 | }
116 |
117 | private fun CustomTabsIntent.Builder.setDarkColorSchemeParams(colorSchemeParams: ColorSchemeParams) {
118 | val customTabColorSchemeParams = CustomTabColorSchemeParams.Builder()
119 |
120 | colorSchemeParams.toolbarColor?.let { customTabColorSchemeParams.setToolbarColor(it.toArgb()) }
121 | colorSchemeParams.secondaryToolbarColor?.let { customTabColorSchemeParams.setSecondaryToolbarColor(it.toArgb()) }
122 | colorSchemeParams.navigationBarColor?.let { customTabColorSchemeParams.setNavigationBarColor(it.toArgb()) }
123 | colorSchemeParams.navigationBarDividerColor?.let { customTabColorSchemeParams.setNavigationBarDividerColor(it.toArgb()) }
124 |
125 | this.setColorSchemeParams(CustomTabsIntent.COLOR_SCHEME_DARK, customTabColorSchemeParams.build())
126 | }
--------------------------------------------------------------------------------
/library/src/commonMain/kotlin/com/final_class/webview_multiplatform_mobile/platform/WebViewPlatformImpl.kt:
--------------------------------------------------------------------------------
1 | package com.final_class.webview_multiplatform_mobile.platform
2 |
3 | import androidx.compose.runtime.Composable
4 | import com.final_class.webview_multiplatform_mobile.webview.settings.android.AndroidSettings
5 | import com.final_class.webview_multiplatform_mobile.webview.settings.ios.IosSettings
6 |
7 | @Composable
8 | internal expect fun WebViewPlatformImpl(
9 | url: String,
10 | openInExternalBrowser: Boolean,
11 | androidSettings: AndroidSettings,
12 | iosSettings: IosSettings,
13 | )
--------------------------------------------------------------------------------
/library/src/commonMain/kotlin/com/final_class/webview_multiplatform_mobile/webview/WebViewPlatform.kt:
--------------------------------------------------------------------------------
1 | package com.final_class.webview_multiplatform_mobile.webview
2 |
3 | import androidx.compose.runtime.Composable
4 | import com.final_class.webview_multiplatform_mobile.platform.WebViewPlatformImpl
5 | import com.final_class.webview_multiplatform_mobile.webview.controller.WebViewController
6 | import com.final_class.webview_multiplatform_mobile.webview.controller.state.WebViewState
7 | import com.final_class.webview_multiplatform_mobile.webview.settings.android.AndroidSettings
8 | import com.final_class.webview_multiplatform_mobile.webview.settings.android.AndroidWebViewModifier
9 | import com.final_class.webview_multiplatform_mobile.webview.settings.ios.IosSettings
10 | import com.final_class.webview_multiplatform_mobile.webview.settings.ios.IosWebViewModifier
11 |
12 | /**
13 | * @param webViewController is needed to manage the launching of WebView
14 | * @param androidSettings settings for Android
15 | * @param iosSettings settings for iOS (The settings are not applied when the openInExternalBrowser value is set to true)
16 | * **/
17 | @Composable
18 | fun WebViewPlatform(
19 | webViewController: WebViewController,
20 | androidSettings: AndroidWebViewModifier = AndroidSettings(),
21 | iosSettings: IosWebViewModifier = IosSettings(),
22 | ) {
23 | when (val state = webViewController.webViewState.value) {
24 | is WebViewState.Close -> return
25 | is WebViewState.Open -> OpenWebView(state.url, state.openInExternalBrowser, androidSettings, iosSettings)
26 | }
27 |
28 | webViewController.consume()
29 | }
30 |
31 | @Composable
32 | internal fun OpenWebView(
33 | url: String,
34 | openInExternalBrowser: Boolean = false,
35 | androidSettings: AndroidWebViewModifier = AndroidSettings(),
36 | iosSettings: IosWebViewModifier = IosSettings(),
37 | ) {
38 | WebViewPlatformImpl(
39 | url = url,
40 | openInExternalBrowser = openInExternalBrowser,
41 | androidSettings = androidSettings.provide(),
42 | iosSettings = iosSettings.provide(),
43 | )
44 | }
--------------------------------------------------------------------------------
/library/src/commonMain/kotlin/com/final_class/webview_multiplatform_mobile/webview/controller/RememberWebViewController.kt:
--------------------------------------------------------------------------------
1 | package com.final_class.webview_multiplatform_mobile.webview.controller
2 |
3 | import androidx.compose.runtime.Composable
4 | import androidx.compose.runtime.remember
5 |
6 | /**
7 | * Created by Dmitry Aleksandrovich on 30.03.2024
8 | **/
9 | @Composable
10 | fun rememberWebViewController(): WebViewController {
11 | return remember { WebViewControllerImpl() }
12 | }
--------------------------------------------------------------------------------
/library/src/commonMain/kotlin/com/final_class/webview_multiplatform_mobile/webview/controller/WebViewController.kt:
--------------------------------------------------------------------------------
1 | package com.final_class.webview_multiplatform_mobile.webview.controller
2 |
3 | import androidx.compose.runtime.State
4 | import com.final_class.webview_multiplatform_mobile.webview.controller.state.WebViewState
5 | import kotlin.properties.ReadOnlyProperty
6 |
7 | /**
8 | * Created by Dmitry Aleksandrovich on 30.03.2024
9 | **/
10 | interface WebViewController : ReadOnlyProperty {
11 |
12 | val webViewState: State
13 |
14 | /** Open in application **/
15 | fun open(url: String)
16 |
17 | /** Open in external browser **/
18 | fun openInExternalBrowser(url: String)
19 |
20 | fun consume()
21 | }
--------------------------------------------------------------------------------
/library/src/commonMain/kotlin/com/final_class/webview_multiplatform_mobile/webview/controller/WebViewControllerImpl.kt:
--------------------------------------------------------------------------------
1 | package com.final_class.webview_multiplatform_mobile.webview.controller
2 |
3 | import androidx.compose.runtime.MutableState
4 | import androidx.compose.runtime.State
5 | import androidx.compose.runtime.mutableStateOf
6 | import com.final_class.webview_multiplatform_mobile.webview.controller.state.WebViewState
7 | import kotlin.reflect.KProperty
8 |
9 | /**
10 | * Created by Dmitry Aleksandrovich on 30.03.2024
11 | **/
12 | class WebViewControllerImpl internal constructor() : WebViewController {
13 |
14 | private val _webViewState: MutableState = mutableStateOf(WebViewState.Close)
15 | override val webViewState: State = _webViewState
16 |
17 | override fun getValue(thisRef: Nothing?, property: KProperty<*>): WebViewController {
18 | return this
19 | }
20 |
21 | override fun open(url: String) {
22 | val verifiedUrl = verifyUrl(url = url)
23 |
24 | _webViewState.value = WebViewState.Open(url = verifiedUrl, openInExternalBrowser = false)
25 | }
26 |
27 | override fun openInExternalBrowser(url: String) {
28 | val verifiedUrl = verifyUrl(url = url)
29 |
30 | _webViewState.value = WebViewState.Open(url = verifiedUrl, openInExternalBrowser = true)
31 | }
32 |
33 | override fun consume() {
34 | _webViewState.value = WebViewState.Close
35 | }
36 |
37 | private fun verifyUrl(url: String): String {
38 | if (url.isBlank()) throw IllegalArgumentException("url cannot be empty")
39 |
40 | return url.trim()
41 | }
42 | }
--------------------------------------------------------------------------------
/library/src/commonMain/kotlin/com/final_class/webview_multiplatform_mobile/webview/controller/state/WebViewState.kt:
--------------------------------------------------------------------------------
1 | package com.final_class.webview_multiplatform_mobile.webview.controller.state
2 |
3 | /**
4 | * Created by Dmitry Aleksandrovich on 30.03.2024
5 | **/
6 | sealed interface WebViewState {
7 | data object Close : WebViewState
8 | data class Open(val url: String, val openInExternalBrowser: Boolean) : WebViewState
9 | }
--------------------------------------------------------------------------------
/library/src/commonMain/kotlin/com/final_class/webview_multiplatform_mobile/webview/settings/android/AndroidSettings.kt:
--------------------------------------------------------------------------------
1 | package com.final_class.webview_multiplatform_mobile.webview.settings.android
2 |
3 | import com.final_class.webview_multiplatform_mobile.webview.settings.android.activity_height.ActivityHeight
4 | import com.final_class.webview_multiplatform_mobile.webview.settings.android.android_scheme_colors.ColorSchemeParams
5 | import com.final_class.webview_multiplatform_mobile.webview.settings.android.animation.AndroidAnimations
6 | import com.final_class.webview_multiplatform_mobile.webview.settings.android.close_button_position.CloseButtonPosition
7 | import com.final_class.webview_multiplatform_mobile.webview.settings.android.scheme.AndroidScheme
8 | import com.final_class.webview_multiplatform_mobile.webview.settings.android.share.ShareState
9 |
10 | data class AndroidSettings(
11 | var showTitle: Boolean? = null,
12 | var urlBarHidingEnabled: Boolean? = null,
13 | var shareState: ShareState? = null,
14 | var instantAppsEnabled: Boolean? = null,
15 | var toolbarCornerRadiusDp: Int? = null,
16 | var activityHeight: ActivityHeight? = null,
17 | var closeButtonPosition: CloseButtonPosition? = null,
18 | var exitAnimation: AndroidAnimations? = null,
19 | var startAnimation: AndroidAnimations? = null,
20 | var scheme: AndroidScheme? = null,
21 | var defaultColorSchemeParams: ColorSchemeParams? = null,
22 | var darkColorSchemeParams: ColorSchemeParams? = null,
23 | ) : AndroidWebViewModifier {
24 |
25 | override fun provide(): AndroidSettings = this
26 | }
27 |
--------------------------------------------------------------------------------
/library/src/commonMain/kotlin/com/final_class/webview_multiplatform_mobile/webview/settings/android/AndroidWebViewModifier.kt:
--------------------------------------------------------------------------------
1 | package com.final_class.webview_multiplatform_mobile.webview.settings.android
2 |
3 | interface AndroidWebViewModifier {
4 |
5 | fun provide(): AndroidSettings
6 |
7 | /**
8 | * The companion object AndroidWebViewModifier is the empty, default, or starter AndroidWebViewModifier that contains no elements.
9 | * Use it to create a new AndroidWebViewModifier using modifier extension factory functions
10 | **/
11 | companion object : AndroidWebViewModifier {
12 | override fun provide(): AndroidSettings = AndroidSettings()
13 | }
14 | }
--------------------------------------------------------------------------------
/library/src/commonMain/kotlin/com/final_class/webview_multiplatform_mobile/webview/settings/android/AndroidWebViewModifierExtensions.kt:
--------------------------------------------------------------------------------
1 | package com.final_class.webview_multiplatform_mobile.webview.settings.android
2 |
3 | import com.final_class.webview_multiplatform_mobile.webview.settings.android.activity_height.ActivityHeight
4 | import com.final_class.webview_multiplatform_mobile.webview.settings.android.android_scheme_colors.ColorSchemeParams
5 | import com.final_class.webview_multiplatform_mobile.webview.settings.android.animation.AndroidAnimations
6 | import com.final_class.webview_multiplatform_mobile.webview.settings.android.close_button_position.CloseButtonPosition
7 | import com.final_class.webview_multiplatform_mobile.webview.settings.android.scheme.AndroidScheme
8 | import com.final_class.webview_multiplatform_mobile.webview.settings.android.share.ShareState
9 |
10 | /**
11 | * @param show sets whether the title should be shown in the custom tab.
12 | **/
13 | fun AndroidWebViewModifier.showTitle(show: Boolean): AndroidWebViewModifier {
14 | return this.then().apply { this.showTitle = show }
15 | }
16 |
17 | /**
18 | * @param enabled set whether the url bar should hide as the user scrolls down on the page.
19 | **/
20 | fun AndroidWebViewModifier.urlBarHidingEnabled(enabled: Boolean): AndroidWebViewModifier {
21 | return this.then().apply { this.urlBarHidingEnabled = enabled }
22 | }
23 |
24 | /**
25 | * @param shareState sets the share state that should be applied to the custom tab.
26 | **/
27 | fun AndroidWebViewModifier.shareState(shareState: ShareState): AndroidWebViewModifier {
28 | return this.then().apply { this.shareState = shareState }
29 | }
30 |
31 | /**
32 | * @param enabled sets whether Instant Apps is enabled for this Custom Tab.
33 | **/
34 | fun AndroidWebViewModifier.instantAppsEnabled(enabled: Boolean): AndroidWebViewModifier {
35 | return this.then().apply { this.instantAppsEnabled = enabled }
36 | }
37 |
38 | /**
39 | * @param radius sets the toolbar's top corner radii in dp.
40 | **/
41 | fun AndroidWebViewModifier.toolbarCornerRadiusDp(radius: Int): AndroidWebViewModifier {
42 | return this.then().apply { this.toolbarCornerRadiusDp = radius }
43 | }
44 |
45 | /**
46 | * @param activityHeight sets the Custom Tab Activity's initial height in pixels and the desired resize behavior.
47 | **/
48 | fun AndroidWebViewModifier.activityHeight(activityHeight: ActivityHeight): AndroidWebViewModifier {
49 | return this.then().apply { this.activityHeight = activityHeight }
50 | }
51 |
52 | /**
53 | * @param closeButtonPosition sets the position of the close button.
54 | **/
55 | fun AndroidWebViewModifier.closeButtonPosition(closeButtonPosition: CloseButtonPosition): AndroidWebViewModifier {
56 | return this.then().apply { this.closeButtonPosition = closeButtonPosition }
57 | }
58 |
59 | /**
60 | * @param animations sets the start animations.
61 | **/
62 | fun AndroidWebViewModifier.startAnimations(animations: AndroidAnimations): AndroidWebViewModifier {
63 | return this.then().apply { this.startAnimation = animations }
64 | }
65 |
66 | /**
67 | * @param animations Sets the exit animations.
68 | **/
69 | fun AndroidWebViewModifier.exitAnimations(animations: AndroidAnimations): AndroidWebViewModifier {
70 | return this.then().apply { this.exitAnimation = animations }
71 | }
72 |
73 | /**
74 | * @param scheme Sets the color scheme that should be applied to the user interface in the custom tab.
75 | **/
76 | fun AndroidWebViewModifier.scheme(scheme: AndroidScheme): AndroidWebViewModifier {
77 | return this.then().apply { this.scheme = scheme }
78 | }
79 |
80 | /**
81 | * @param colorSchemeParams sets the default CustomTabColorSchemeParams.
82 | * This will set a default color scheme that applies when no AndroidScheme
83 | * specified for current color scheme via scheme.
84 | **/
85 | fun AndroidWebViewModifier.defaultColorSchemeParams(colorSchemeParams: ColorSchemeParams): AndroidWebViewModifier {
86 | return this.then().apply { this.defaultColorSchemeParams = colorSchemeParams }
87 | }
88 |
89 | /**
90 | * @param colorSchemeParams sets the dark CustomTabColorSchemeParams.
91 | * * This will set a dark color scheme that applies when AndroidScheme.Dark
92 | * * specified for current color scheme via scheme.
93 | **/
94 | fun AndroidWebViewModifier.darkColorSchemeParams(colorSchemeParams: ColorSchemeParams): AndroidWebViewModifier {
95 | return this.then().apply { this.darkColorSchemeParams = colorSchemeParams }
96 | }
97 |
98 | internal fun AndroidWebViewModifier.then(): AndroidSettings = if (this is AndroidSettings) this else AndroidSettings()
--------------------------------------------------------------------------------
/library/src/commonMain/kotlin/com/final_class/webview_multiplatform_mobile/webview/settings/android/activity_height/ActivityHeight.kt:
--------------------------------------------------------------------------------
1 | package com.final_class.webview_multiplatform_mobile.webview.settings.android.activity_height
2 |
3 | /**
4 | * @param initialHeightPx the Custom Tab Activity's initial height in pixels.
5 | * @param heightResizeBehavior desired height behavior.
6 | **/
7 | data class ActivityHeight(
8 | val initialHeightPx: Int,
9 | val heightResizeBehavior: HeightResizeBehavior? = null,
10 | )
11 |
--------------------------------------------------------------------------------
/library/src/commonMain/kotlin/com/final_class/webview_multiplatform_mobile/webview/settings/android/activity_height/HeightResizeBehavior.kt:
--------------------------------------------------------------------------------
1 | package com.final_class.webview_multiplatform_mobile.webview.settings.android.activity_height
2 |
3 | enum class HeightResizeBehavior {
4 | /** Applies the default height resize behavior for the Custom Tab Activity when it behaves as a bottom sheet. **/
5 | ACTIVITY_HEIGHT_DEFAULT,
6 |
7 | /** The Custom Tab Activity, when it behaves as a bottom sheet, can have its height manually resized by the user. **/
8 | ACTIVITY_HEIGHT_ADJUSTABLE,
9 |
10 | /** The Custom Tab Activity, when it behaves as a bottom sheet, cannot have its height manually resized by the user. **/
11 | ACTIVITY_HEIGHT_FIXED;
12 | }
--------------------------------------------------------------------------------
/library/src/commonMain/kotlin/com/final_class/webview_multiplatform_mobile/webview/settings/android/android_scheme_colors/ColorSchemeParams.kt:
--------------------------------------------------------------------------------
1 | package com.final_class.webview_multiplatform_mobile.webview.settings.android.android_scheme_colors
2 |
3 | import androidx.compose.ui.graphics.Color
4 |
5 | /**
6 | * @param toolbarColor sets the toolbar color. On Android L and above, this color is also applied to the status bar.
7 | * To ensure good contrast between status bar icons and the background,
8 | * Custom Tab implementations may use SYSTEM_UI_FLAG_LIGHT_STATUS_BAR on Android M and above,
9 | * and use a darkened color for the status bar on Android L.
10 | * @param secondaryToolbarColor sets the color of the secondary toolbar.
11 | * @param navigationBarColor sets the navigation bar color. Has no effect on API versions below L.
12 | * To ensure good contrast between navigation bar icons and the background,
13 | * Custom Tab implementations may use SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR on Android O and above,
14 | * and darken the provided color on Android L-N.
15 | * @param navigationBarDividerColor sets the navigation bar divider color. Has no effect on API versions below P.
16 | **/
17 | data class ColorSchemeParams(
18 | val toolbarColor: Color? = null,
19 | val secondaryToolbarColor: Color? = null,
20 | val navigationBarColor: Color? = null,
21 | val navigationBarDividerColor: Color? = null
22 | )
23 |
--------------------------------------------------------------------------------
/library/src/commonMain/kotlin/com/final_class/webview_multiplatform_mobile/webview/settings/android/animation/AndroidAnimations.kt:
--------------------------------------------------------------------------------
1 | package com.final_class.webview_multiplatform_mobile.webview.settings.android.animation
2 |
3 | /**
4 | * @param enterResId resource ID of the "enter" animation for the browser.
5 | * @param exitResId resource ID of the "exit" animation for the application.
6 | **/
7 | data class AndroidAnimations(
8 | val enterResId: Int,
9 | val exitResId: Int,
10 | )
11 |
--------------------------------------------------------------------------------
/library/src/commonMain/kotlin/com/final_class/webview_multiplatform_mobile/webview/settings/android/close_button_position/CloseButtonPosition.kt:
--------------------------------------------------------------------------------
1 | package com.final_class.webview_multiplatform_mobile.webview.settings.android.close_button_position
2 |
3 | enum class CloseButtonPosition {
4 | /** Same as CLOSE_BUTTON_POSITION_START. **/
5 | DEFAULT,
6 |
7 | /** Positions the close button at the start of the toolbar. **/
8 | START,
9 |
10 | /** Positions the close button at the end of the toolbar. **/
11 | END;
12 | }
--------------------------------------------------------------------------------
/library/src/commonMain/kotlin/com/final_class/webview_multiplatform_mobile/webview/settings/android/scheme/AndroidScheme.kt:
--------------------------------------------------------------------------------
1 | package com.final_class.webview_multiplatform_mobile.webview.settings.android.scheme
2 |
3 | enum class AndroidScheme {
4 | /** Applies either a light or dark color scheme to the user interface in the custom tab depending on the user's system settings. **/
5 | System,
6 |
7 | /** Applies a light color scheme to the user interface in the custom tab. **/
8 | Light,
9 |
10 | /** Applies a dark color scheme to the user interface in the custom tab. Colors set through EXTRA_TOOLBAR_COLOR may be darkened to match user expectations. **/
11 | Dark;
12 | }
--------------------------------------------------------------------------------
/library/src/commonMain/kotlin/com/final_class/webview_multiplatform_mobile/webview/settings/android/share/ShareState.kt:
--------------------------------------------------------------------------------
1 | package com.final_class.webview_multiplatform_mobile.webview.settings.android.share
2 |
3 | enum class ShareState {
4 | /** Applies the default share settings depending on the browser. **/
5 | SHARE_STATE_DEFAULT,
6 |
7 | /** Explicitly does not show a share option in the tab. **/
8 | SHARE_STATE_OFF,
9 |
10 | /** Shows a share option in the tab. **/
11 | SHARE_STATE_ON;
12 | }
--------------------------------------------------------------------------------
/library/src/commonMain/kotlin/com/final_class/webview_multiplatform_mobile/webview/settings/ios/IosSettings.kt:
--------------------------------------------------------------------------------
1 | package com.final_class.webview_multiplatform_mobile.webview.settings.ios
2 |
3 | import androidx.compose.ui.graphics.Color
4 | import com.final_class.webview_multiplatform_mobile.webview.settings.ios.dismiss_button_style.DismissButtonStyle
5 |
6 | data class IosSettings(
7 | var barCollapsingEnabled: Boolean? = null,
8 | var entersReaderIfAvailable: Boolean? = null,
9 | var dismissButtonStyle: DismissButtonStyle? = null,
10 | var preferredBarTintColor: Color? = null,
11 | var preferredControlTintColor: Color? = null,
12 | ) : IosWebViewModifier {
13 | override fun provide(): IosSettings = this
14 | }
15 |
--------------------------------------------------------------------------------
/library/src/commonMain/kotlin/com/final_class/webview_multiplatform_mobile/webview/settings/ios/IosWebViewModifier.kt:
--------------------------------------------------------------------------------
1 | package com.final_class.webview_multiplatform_mobile.webview.settings.ios
2 |
3 |
4 | interface IosWebViewModifier {
5 |
6 | fun provide(): IosSettings
7 |
8 | companion object : IosWebViewModifier {
9 | override fun provide(): IosSettings = IosSettings()
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/library/src/commonMain/kotlin/com/final_class/webview_multiplatform_mobile/webview/settings/ios/IosWebViewModifierExtensions.kt:
--------------------------------------------------------------------------------
1 | package com.final_class.webview_multiplatform_mobile.webview.settings.ios
2 |
3 | import androidx.compose.ui.graphics.Color
4 | import com.final_class.webview_multiplatform_mobile.webview.settings.ios.dismiss_button_style.DismissButtonStyle
5 |
6 |
7 | /**
8 | * @param enabled enabled bar collapsing.
9 | **/
10 | fun IosWebViewModifier.barCollapsingEnabled(enabled: Boolean): IosWebViewModifier {
11 | return this.then().apply { this.barCollapsingEnabled = enabled }
12 | }
13 |
14 | /**
15 | * @param entersReader a value that specifies whether Safari should enter Reader mode, if it is available.
16 | * **/
17 | fun IosWebViewModifier.entersReaderIfAvailable(entersReader: Boolean): IosWebViewModifier {
18 | return this.then().apply { this.entersReaderIfAvailable = entersReader }
19 | }
20 |
21 | /**
22 | * @param buttonStyle sets dismiss button style.
23 | * **/
24 | fun IosWebViewModifier.dismissButtonStyle(buttonStyle: DismissButtonStyle): IosWebViewModifier {
25 | return this.then().apply { this.dismissButtonStyle = buttonStyle }
26 | }
27 |
28 | /**
29 | * @param color the color to tint the background of the navigation bar and the toolbar.
30 | * **/
31 | fun IosWebViewModifier.preferredBarTintColor(color: Color): IosWebViewModifier {
32 | return this.then().apply { this.preferredBarTintColor = color }
33 | }
34 |
35 | /**
36 | * @param color the color to tint the control buttons on the navigation bar and the toolbar.
37 | * **/
38 | fun IosWebViewModifier.preferredControlTintColor(color: Color): IosWebViewModifier {
39 | return this.then().apply { this.preferredControlTintColor = color }
40 | }
41 |
42 | internal fun IosWebViewModifier.then(): IosSettings = if (this is IosSettings) this else IosSettings()
--------------------------------------------------------------------------------
/library/src/commonMain/kotlin/com/final_class/webview_multiplatform_mobile/webview/settings/ios/dismiss_button_style/DismissButtonStyle.kt:
--------------------------------------------------------------------------------
1 | package com.final_class.webview_multiplatform_mobile.webview.settings.ios.dismiss_button_style
2 |
3 | enum class DismissButtonStyle {
4 | Close,
5 | Cancel,
6 | Done;
7 | }
--------------------------------------------------------------------------------
/library/src/iosMain/kotlin/com/final_class/webview_multiplatform_mobile/platform/WebViewPlatformImpl.kt:
--------------------------------------------------------------------------------
1 | package com.final_class.webview_multiplatform_mobile.platform
2 |
3 | import androidx.compose.runtime.Composable
4 | import androidx.compose.ui.graphics.Color
5 | import com.final_class.webview_multiplatform_mobile.webview.settings.android.AndroidSettings
6 | import com.final_class.webview_multiplatform_mobile.webview.settings.ios.IosSettings
7 | import com.final_class.webview_multiplatform_mobile.webview.settings.ios.dismiss_button_style.DismissButtonStyle
8 | import platform.Foundation.NSURL
9 | import platform.SafariServices.SFSafariViewController
10 | import platform.SafariServices.SFSafariViewControllerConfiguration
11 | import platform.SafariServices.SFSafariViewControllerDismissButtonStyle
12 | import platform.UIKit.UIApplication
13 | import platform.UIKit.UIColor
14 |
15 | @Composable
16 | internal actual fun WebViewPlatformImpl(
17 | url: String,
18 | openInExternalBrowser: Boolean,
19 | androidSettings: AndroidSettings,
20 | iosSettings: IosSettings,
21 | ) {
22 | val nsurl = NSURL(string = url)
23 | val safariConfiguration = createSafariConfiguration(iosSettings = iosSettings)
24 | val safariViewController = createSafariViewController(
25 | url = nsurl,
26 | configuration = safariConfiguration,
27 | iosSettings = iosSettings
28 | )
29 |
30 | if (openInExternalBrowser) {
31 | UIApplication.sharedApplication.openURL(url = nsurl, options = emptyMap(), completionHandler = null)
32 | } else {
33 | val viewController = UIApplication.sharedApplication.keyWindow?.rootViewController
34 | viewController?.presentViewController(safariViewController, animated = true, completion = null)
35 | }
36 | }
37 |
38 | private fun createSafariViewController(
39 | url: NSURL,
40 | configuration: SFSafariViewControllerConfiguration,
41 | iosSettings: IosSettings
42 | ): SFSafariViewController {
43 | return SFSafariViewController(uRL = url, configuration = configuration).apply {
44 | iosSettings.dismissButtonStyle?.let { setDismissButtonStyle(it) }
45 | iosSettings.preferredBarTintColor?.let { setPreferredBarTintColor(it.toUIColor()) }
46 | iosSettings.preferredControlTintColor?.let { setPreferredControlTintColor(it.toUIColor()) }
47 | }
48 | }
49 |
50 | private fun createSafariConfiguration(iosSettings: IosSettings): SFSafariViewControllerConfiguration {
51 | return SFSafariViewControllerConfiguration().apply {
52 | iosSettings.barCollapsingEnabled?.let { setBarCollapsingEnabled(it) }
53 | iosSettings.entersReaderIfAvailable?.let { setEntersReaderIfAvailable(it) }
54 | }
55 | }
56 |
57 | private fun SFSafariViewController.setDismissButtonStyle(dismissButtonStyle: DismissButtonStyle) {
58 | val buttonStyle = when (dismissButtonStyle) {
59 | DismissButtonStyle.Close -> SFSafariViewControllerDismissButtonStyle.SFSafariViewControllerDismissButtonStyleClose
60 | DismissButtonStyle.Cancel -> SFSafariViewControllerDismissButtonStyle.SFSafariViewControllerDismissButtonStyleCancel
61 | DismissButtonStyle.Done -> SFSafariViewControllerDismissButtonStyle.SFSafariViewControllerDismissButtonStyleDone
62 | }
63 |
64 | this.dismissButtonStyle = buttonStyle
65 | }
66 |
67 | private fun Color.toUIColor(): UIColor = UIColor(
68 | red = this.red.toDouble(),
69 | green = this.green.toDouble(),
70 | blue = this.blue.toDouble(),
71 | alpha = this.alpha.toDouble()
72 | )
--------------------------------------------------------------------------------
/sample/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | alias(libs.plugins.kotlinMultiplatform)
3 | alias(libs.plugins.androidApplication)
4 | alias(libs.plugins.jetbrainsCompose)
5 | }
6 |
7 | kotlin {
8 | androidTarget {
9 | compilations.all {
10 | kotlinOptions {
11 | jvmTarget = "11"
12 | }
13 | }
14 | }
15 |
16 | listOf(
17 | iosX64(),
18 | iosArm64(),
19 | iosSimulatorArm64()
20 | ).forEach { iosTarget ->
21 | iosTarget.binaries.framework {
22 | baseName = "Sample"
23 | isStatic = true
24 | }
25 | }
26 |
27 | sourceSets {
28 | androidMain.dependencies {
29 | implementation(libs.compose.ui.tooling.preview)
30 | implementation(libs.androidx.activity.compose)
31 | }
32 | commonMain.dependencies {
33 | /** Compose **/
34 | implementation(compose.runtime)
35 | implementation(compose.foundation)
36 | implementation(compose.material)
37 | implementation(compose.ui)
38 | @OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
39 | implementation(compose.components.resources)
40 | implementation(compose.components.uiToolingPreview)
41 |
42 | /** WebView Multiplatform Mobile **/
43 | implementation(projects.library)
44 | }
45 | }
46 | }
47 |
48 | android {
49 | namespace = "com.final_class.sample_webview_multiplatform_mobile"
50 | compileSdk = libs.versions.android.compileSdk.get().toInt()
51 |
52 | sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
53 | sourceSets["main"].res.srcDirs("src/androidMain/res")
54 | sourceSets["main"].resources.srcDirs("src/commonMain/resources")
55 |
56 | defaultConfig {
57 | applicationId = "com.final_class.sample_webview_multiplatform_mobile"
58 | minSdk = libs.versions.android.minSdk.get().toInt()
59 | targetSdk = libs.versions.android.targetSdk.get().toInt()
60 | versionCode = 1
61 | versionName = "1.0"
62 | }
63 | packaging {
64 | resources {
65 | excludes += "/META-INF/{AL2.0,LGPL2.1}"
66 | }
67 | }
68 | buildTypes {
69 | getByName("release") {
70 | isMinifyEnabled = false
71 | }
72 | }
73 | compileOptions {
74 | sourceCompatibility = JavaVersion.VERSION_11
75 | targetCompatibility = JavaVersion.VERSION_11
76 | }
77 | dependencies {
78 | debugImplementation(libs.compose.ui.tooling)
79 | }
80 | }
--------------------------------------------------------------------------------
/sample/src/androidMain/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/sample/src/androidMain/kotlin/com/final_class/sample_webview_multiplatform_mobile/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.final_class.sample_webview_multiplatform_mobile
2 |
3 | import App
4 | import android.os.Bundle
5 | import androidx.activity.ComponentActivity
6 | import androidx.activity.compose.setContent
7 | import androidx.compose.runtime.Composable
8 | import androidx.compose.ui.tooling.preview.Preview
9 |
10 | class MainActivity : ComponentActivity() {
11 | override fun onCreate(savedInstanceState: Bundle?) {
12 | super.onCreate(savedInstanceState)
13 |
14 | setContent {
15 | App()
16 | }
17 | }
18 | }
19 |
20 | @Preview
21 | @Composable
22 | fun AppAndroidPreview() {
23 | App()
24 | }
--------------------------------------------------------------------------------
/sample/src/androidMain/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/sample/src/androidMain/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/sample/src/androidMain/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/sample/src/androidMain/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/sample/src/androidMain/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/final-class/WebView-Multiplatform-Mobile/46d256c27771aa5f5fd954545755a5d18a2db035/sample/src/androidMain/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/androidMain/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/final-class/WebView-Multiplatform-Mobile/46d256c27771aa5f5fd954545755a5d18a2db035/sample/src/androidMain/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample/src/androidMain/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/final-class/WebView-Multiplatform-Mobile/46d256c27771aa5f5fd954545755a5d18a2db035/sample/src/androidMain/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/androidMain/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/final-class/WebView-Multiplatform-Mobile/46d256c27771aa5f5fd954545755a5d18a2db035/sample/src/androidMain/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample/src/androidMain/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/final-class/WebView-Multiplatform-Mobile/46d256c27771aa5f5fd954545755a5d18a2db035/sample/src/androidMain/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/androidMain/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/final-class/WebView-Multiplatform-Mobile/46d256c27771aa5f5fd954545755a5d18a2db035/sample/src/androidMain/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample/src/androidMain/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/final-class/WebView-Multiplatform-Mobile/46d256c27771aa5f5fd954545755a5d18a2db035/sample/src/androidMain/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/androidMain/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/final-class/WebView-Multiplatform-Mobile/46d256c27771aa5f5fd954545755a5d18a2db035/sample/src/androidMain/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample/src/androidMain/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/final-class/WebView-Multiplatform-Mobile/46d256c27771aa5f5fd954545755a5d18a2db035/sample/src/androidMain/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/androidMain/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/final-class/WebView-Multiplatform-Mobile/46d256c27771aa5f5fd954545755a5d18a2db035/sample/src/androidMain/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample/src/androidMain/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Sample WebView Multiplatform Mobile
3 |
--------------------------------------------------------------------------------
/sample/src/commonMain/kotlin/App.kt:
--------------------------------------------------------------------------------
1 | import androidx.compose.foundation.background
2 | import androidx.compose.foundation.layout.Column
3 | import androidx.compose.foundation.layout.fillMaxSize
4 | import androidx.compose.foundation.layout.fillMaxWidth
5 | import androidx.compose.foundation.layout.padding
6 | import androidx.compose.foundation.shape.RoundedCornerShape
7 | import androidx.compose.foundation.text.KeyboardOptions
8 | import androidx.compose.material.Button
9 | import androidx.compose.material.ButtonDefaults
10 | import androidx.compose.material.MaterialTheme
11 | import androidx.compose.material.OutlinedTextField
12 | import androidx.compose.material.Text
13 | import androidx.compose.runtime.Composable
14 | import androidx.compose.runtime.getValue
15 | import androidx.compose.runtime.mutableStateOf
16 | import androidx.compose.runtime.remember
17 | import androidx.compose.runtime.setValue
18 | import androidx.compose.ui.Alignment
19 | import androidx.compose.ui.Modifier
20 | import androidx.compose.ui.graphics.Color
21 | import androidx.compose.ui.text.font.FontWeight
22 | import androidx.compose.ui.text.input.ImeAction
23 | import androidx.compose.ui.text.input.KeyboardType
24 | import androidx.compose.ui.text.style.TextAlign
25 | import androidx.compose.ui.unit.dp
26 | import androidx.compose.ui.unit.sp
27 | import com.final_class.webview_multiplatform_mobile.webview.WebViewPlatform
28 | import com.final_class.webview_multiplatform_mobile.webview.controller.rememberWebViewController
29 | import org.jetbrains.compose.ui.tooling.preview.Preview
30 |
31 | @Composable
32 | fun App() {
33 | MaterialTheme {
34 | val webViewController by rememberWebViewController()
35 |
36 | var openWebView by remember {
37 | mutableStateOf(false)
38 | }
39 | var url by remember {
40 | mutableStateOf("https://github.com/final-class/WebView-Multiplatform-Mobile")
41 | }
42 |
43 | WebViewPlatform(webViewController = webViewController)
44 |
45 | Column(
46 | modifier = Modifier.fillMaxSize(),
47 | horizontalAlignment = Alignment.CenterHorizontally,
48 | ) {
49 | Text(
50 | modifier = Modifier
51 | .fillMaxWidth()
52 | .padding(top = 40.dp),
53 | text = "WebView Multiplatform Mobile",
54 | fontSize = 18.sp,
55 | textAlign = TextAlign.Center,
56 | fontWeight = FontWeight.SemiBold
57 | )
58 |
59 | OutlinedTextField(
60 | modifier = Modifier
61 | .fillMaxWidth()
62 | .padding(top = 40.dp, start = 20.dp, end = 20.dp),
63 | value = url,
64 | onValueChange = { url = it },
65 | label = { Text("Url") },
66 | keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Uri, imeAction = ImeAction.Done),
67 | )
68 |
69 | Button(
70 | modifier = Modifier
71 | .fillMaxWidth()
72 | .background(color = Color.White)
73 | .padding(top = 20.dp, start = 20.dp, end = 20.dp),
74 | shape = RoundedCornerShape(16.dp),
75 | colors = ButtonDefaults.buttonColors(backgroundColor = MaterialTheme.colors.secondary),
76 | onClick = { url = "" }
77 | ) {
78 | Text(
79 | text = "Clear URL",
80 | color = Color.Black
81 | )
82 | }
83 |
84 | Button(
85 | modifier = Modifier
86 | .fillMaxWidth()
87 | .padding(top = 12.dp, start = 20.dp, end = 20.dp),
88 | shape = RoundedCornerShape(16.dp),
89 | onClick = {
90 | webViewController.open(url = url)
91 | }
92 | ) {
93 | Text("Open WebView")
94 | }
95 |
96 | Button(
97 | modifier = Modifier
98 | .fillMaxWidth()
99 | .padding(top = 12.dp, start = 20.dp, end = 20.dp),
100 | shape = RoundedCornerShape(16.dp),
101 | onClick = {
102 | webViewController.openInExternalBrowser(url = url)
103 | }
104 | ) {
105 | Text("Open external browser")
106 | }
107 | }
108 | }
109 | }
110 |
111 | @Preview
112 | @Composable
113 | fun AppPreview() {
114 | App()
115 | }
--------------------------------------------------------------------------------
/sample/src/iosMain/kotlin/MainViewController.kt:
--------------------------------------------------------------------------------
1 | import androidx.compose.ui.window.ComposeUIViewController
2 |
3 | fun MainViewController() = ComposeUIViewController { App() }
--------------------------------------------------------------------------------
/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
2 | pluginManagement {
3 | repositories {
4 | maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
5 | google()
6 | gradlePluginPortal()
7 | mavenCentral()
8 | }
9 | }
10 |
11 | dependencyResolutionManagement {
12 | repositories {
13 | google()
14 | mavenCentral()
15 | maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
16 | }
17 | }
18 |
19 | rootProject.name = "WebView_Multiplatform_Mobile"
20 | include(":library")
21 | include(":sample")
--------------------------------------------------------------------------------
/static/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/final-class/WebView-Multiplatform-Mobile/46d256c27771aa5f5fd954545755a5d18a2db035/static/logo.png
--------------------------------------------------------------------------------