WebContainer
Description
Web Container is a simple web container library for Android to help fellow developer to open WebView easily and we made it with a simple syntax. This library is written in Kotlin and published in JitPack.io
How To Install
Step 1. Add the JitPack repository to your build file
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
implementation 'com.github.ichsanachmad:WebContainer:${version}'
}
How to Use
Initialization WebContainer on Application
Application.kt (Kotlin):
WebContainer.init(application: Application)
AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
...>
<application
android:name=".Application"
...
</application>
</manifest>
Simple Usage WebContainer
without Swipe Refresh
Kotlin:
WebContainer.launch(url: String)
with Swipe Refresh
Kotlin:
WebContainer.launch(url: String, enableSwipeRefresh: Boolean)
WebContainer with Callback Listener
without Swipe Refresh
Kotlin:
WebContainer.launch(Url: String, object:WebContainerListener {
override fun callback(json: String) {
// ToDo
}
})
with Swipe Refresh
Kotlin:
WebContainer.launch(Url: String, object:WebContainerListener {
override fun callback(json: String) {
// ToDo
}
}, enableSwipeRefresh: Boolean)
Trigger Callback from Web
HTML/JS:
<input type="button" value="Say hello" onClick="showAndroidToast('Hello Android!')" />
<script type="text/javascript">
function showAndroidToast(message) {
AndroidAppCallback.callback(message);
}
</script>
React JS :
class ClassA extends React.PureComponent {
...
private handleRedirect = () => {
if (window.AndroidAppCallback)
window.AndroidAppCallback.callback("Test");
};
}
Extension
Check is URL
Kotlin:
String.isUrl() // For Checking your String is Valid URL or Not