Skip to content

Commit

Permalink
Merge pull request #88 from icerockdev/develop
Browse files Browse the repository at this point in the history
Release 0.1.0 dev 11
  • Loading branch information
Alex009 authored Feb 11, 2020
2 parents f837600 + b4a0cb2 commit 5ad5080
Show file tree
Hide file tree
Showing 52 changed files with 1,874 additions and 273 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This is a Kotlin MultiPlatform library that provides declarative UI and applicat
in common code. You can implement full application for Android and iOS only from common code with it.

## Current status
Current version - `0.1.0-dev-10`. Dev version is not tested in production tasks yet, API can be changed and
Current version - `0.1.0-dev-11`. Dev version is not tested in production tasks yet, API can be changed and
bugs may be found. But dev version is chance to test limits of API and concepts to feedback and improve lib.
We open for any feedback and ideas (go to issues or #moko at [kotlinlang.slack.com](https://kotlinlang.slack.com))!

Expand Down Expand Up @@ -217,6 +217,7 @@ val loginScreen = Theme(baseTheme) {
- 0.1.0-dev-8
- 0.1.0-dev-9
- 0.1.0-dev-10
- 0.1.0-dev-11

## Installation
root build.gradle
Expand All @@ -231,7 +232,7 @@ allprojects {
project build.gradle
```groovy
dependencies {
commonMainApi("dev.icerock.moko:widgets:0.1.0-dev-10")
commonMainApi("dev.icerock.moko:widgets:0.1.0-dev-11")
}
```

Expand All @@ -249,7 +250,7 @@ buildscript {
}
dependencies {
classpath "dev.icerock.moko.widgets:gradle-plugin:0.1.0-dev-10"
classpath "dev.icerock.moko.widgets:gradle-plugin:0.1.0-dev-11"
}
}
Expand Down
3 changes: 3 additions & 0 deletions buildSrc/src/main/kotlin/Deps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ object Deps {
val glide = AndroidLibrary(
name = "com.github.bumptech.glide:glide:${Versions.Libs.Android.glide}"
)
val roundedImageView = AndroidLibrary(
name = "com.makeramen:roundedimageview:${Versions.Libs.Android.roundedImageView}"
)
}

object MultiPlatform {
Expand Down
7 changes: 4 additions & 3 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ object Versions {
}

const val kotlin = "1.3.61"
private const val mokoWidgets = "0.1.0-dev-10"
private const val mokoResources = "0.7.0"
private const val mokoWidgets = "0.1.0-dev-11"
private const val mokoResources = "0.8.0"

object Plugins {
const val mokoWidgets = Versions.mokoWidgets
Expand All @@ -22,12 +22,13 @@ object Versions {
object Android {
const val appCompat = "1.1.0"
const val swipeRefreshLayout = "1.0.0"
const val material = "1.0.0"
const val material = "1.1.0"
const val constraintLayout = "1.1.3"
const val lifecycle = "2.0.0"
const val recyclerView = "1.0.0"
const val inputMask = "5.0.0"
const val glide = "4.10.0"
const val roundedImageView = "2.3.0"
}

object MultiPlatform {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ class MainApplication : Application() {
override fun onCreate() {
super.onCreate()

mppApp = App().apply {
setup()
}
mppApp = App().apply { initialize() }
}

companion object {
Expand Down
4 changes: 2 additions & 2 deletions sample/ios-app/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ SPEC CHECKSUMS:
MultiPlatformLibraryMvvm: 999ac3896d8214fd65e0e0a376a2e553bf4515b3
SkyFloatingLabelTextField: 4b46db0ab1ccde0919cded29c656e6b4805eda04

PODFILE CHECKSUM: 28883f836bd0d431cc3d548bcfba9f7b496c17f6
PODFILE CHECKSUM: b2d99b49a98817d6b9e5a4dd2b7596b74ced0389

COCOAPODS: 1.8.3
COCOAPODS: 1.8.4
2 changes: 1 addition & 1 deletion sample/ios-app/src/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {

let app = App()
app.setup()
app.initialize()

let screen = app.rootScreen.instantiate()
let rootViewController = screen.createViewController()
Expand Down
50 changes: 47 additions & 3 deletions sample/mpp-library/src/commonMain/kotlin/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.icerockdev.library.AppTheme
import com.icerockdev.library.MR
import com.icerockdev.library.SharedFactory
import com.icerockdev.library.universal.CartScreen
import com.icerockdev.library.universal.InfoWebViewScreen
import com.icerockdev.library.universal.LoginScreen
import com.icerockdev.library.universal.LoginViewModel
import com.icerockdev.library.universal.PlatformProfileScreen
Expand All @@ -18,11 +19,15 @@ import dev.icerock.moko.parcelize.Parcelable
import dev.icerock.moko.parcelize.Parcelize
import dev.icerock.moko.resources.desc.desc
import dev.icerock.moko.widgets.ButtonWidget
import dev.icerock.moko.widgets.ImageWidget
import dev.icerock.moko.widgets.InputWidget
import dev.icerock.moko.widgets.button
import dev.icerock.moko.widgets.container
import dev.icerock.moko.widgets.core.Theme
import dev.icerock.moko.widgets.core.Value
import dev.icerock.moko.widgets.factory.ButtonWithIconViewFactory
import dev.icerock.moko.widgets.factory.IconGravity
import dev.icerock.moko.widgets.factory.SystemImageViewFactory
import dev.icerock.moko.widgets.factory.SystemInputViewFactory
import dev.icerock.moko.widgets.flat.FlatInputViewFactory
import dev.icerock.moko.widgets.screen.Args
Expand All @@ -36,10 +41,16 @@ import dev.icerock.moko.widgets.screen.navigation.NavigationBar
import dev.icerock.moko.widgets.screen.navigation.NavigationItem
import dev.icerock.moko.widgets.screen.navigation.NavigationScreen
import dev.icerock.moko.widgets.screen.navigation.Resultable
import dev.icerock.moko.widgets.screen.navigation.SelectStates
import dev.icerock.moko.widgets.screen.navigation.createPushResultRoute
import dev.icerock.moko.widgets.screen.navigation.createPushRoute
import dev.icerock.moko.widgets.screen.navigation.createReplaceRoute
import dev.icerock.moko.widgets.screen.navigation.createRouter
import dev.icerock.moko.widgets.style.background.Background
import dev.icerock.moko.widgets.style.background.Fill
import dev.icerock.moko.widgets.style.background.StateBackground
import dev.icerock.moko.widgets.style.view.CornerRadiusValue
import dev.icerock.moko.widgets.style.view.PaddingValues
import dev.icerock.moko.widgets.style.view.TextStyle
import dev.icerock.moko.widgets.style.view.WidgetSize

Expand All @@ -57,6 +68,20 @@ class App() : BaseApplication() {
),
backgroundColor = Color(0xF5F5F5FF)
)
factory[LoginScreen.Id.RegistrationButtonId] = ButtonWithIconViewFactory(
icon = MR.images.stars_black_18,
iconGravity = IconGravity.TEXT_END,
iconPadding = 8.0f,
padding = PaddingValues(padding = 16f),
background = StateBackground(
normal = Background(fill = Fill.Solid(color = Color(0xAAFFFFFF))),
pressed = Background(fill = Fill.Solid(color = Color(0x88FFFFFF))),
disabled = Background(fill = Fill.Solid(color = Color(0x55FFFFFF)))
)
)
factory[ImageWidget.DefaultCategory] = SystemImageViewFactory(
cornerRadiusValue = CornerRadiusValue(16.0f)
)
}

val widgetsTheme = Theme(theme) {
Expand Down Expand Up @@ -119,7 +144,8 @@ class App() : BaseApplication() {
tab(
id = 1,
title = "Products".desc(),
icon = MR.images.home_black_18,
selectedIcon = MR.images.cart_black_18,
unselectedIcon = MR.images.home_black_18,
screenDesc = productsNavigation
)
tab(
Expand All @@ -137,18 +163,27 @@ class App() : BaseApplication() {
}
}

return registerScreen(NavigationScreen::class) {
return registerScreen(RootNavigationScreen::class) {
val router = createRouter()

val regScreen = registerScreen(RegisterScreen::class) {
RegisterScreen(theme)
}

val oauthScreen = registerScreen(InfoWebViewScreen::class) {
InfoWebViewScreen(
theme = loginTheme
)
}

val loginScreen = registerScreen(LoginScreen::class) {
LoginScreen(
theme = loginTheme,
mainRoute = router.createReplaceRoute(mainScreen),
registerRoute = router.createPushResultRoute(regScreen) { it.token }
registerRoute = router.createPushResultRoute(regScreen) { it.token },
infoWebViewRoute = router.createPushRoute(oauthScreen) {
InfoWebViewScreen.WebViewArgs(it)
}
) { LoginViewModel(it) }
}

Expand Down Expand Up @@ -190,6 +225,15 @@ class MainBottomNavigationScreen(
builder: BottomNavigationItem.Builder.() -> Unit
) : BottomNavigationScreen(router, builder), NavigationItem {
override val navigationBar: NavigationBar = NavigationBar.None

init {
bottomNavigationColor = Color(0x6518f4FF)

itemStateColors = SelectStates(
selected = Color(0xfdfffdFF),
unselected = Color(0xc0a3f9FF)
)
}
}

class RootNavigationScreen(initialScreen: TypedScreenDesc<Args.Empty, LoginScreen>, router: Router) :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class CartScreen(
size = WidgetSize.WrapContent,
content = ButtonWidget.Content.Text(Value.data("profile".desc()))
) {
profileRoute.route(this@CartScreen, 10)
profileRoute.route(10)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
*/

package com.icerockdev.library.universal

import dev.icerock.moko.mvvm.livedata.MutableLiveData
import dev.icerock.moko.parcelize.Parcelable
import dev.icerock.moko.parcelize.Parcelize
import dev.icerock.moko.resources.desc.desc
import dev.icerock.moko.widgets.constraint
import dev.icerock.moko.widgets.core.Theme
import dev.icerock.moko.widgets.core.Widget
import dev.icerock.moko.widgets.progressBar
import dev.icerock.moko.widgets.screen.Args
import dev.icerock.moko.widgets.screen.WidgetScreen
import dev.icerock.moko.widgets.screen.getArgument
import dev.icerock.moko.widgets.screen.navigation.NavigationBar
import dev.icerock.moko.widgets.screen.navigation.NavigationItem
import dev.icerock.moko.widgets.style.view.SizeSpec
import dev.icerock.moko.widgets.style.view.WidgetSize
import dev.icerock.moko.widgets.visibility
import dev.icerock.moko.widgets.webView

class InfoWebViewScreen(
private val theme: Theme
) : WidgetScreen<Args.Parcel<InfoWebViewScreen.WebViewArgs>>(), NavigationItem {

override val navigationBar: NavigationBar = NavigationBar.Normal("WebView Sample".desc())

override fun createContentWidget(): Widget<WidgetSize.Const<SizeSpec.AsParent, SizeSpec.AsParent>> {
val inputArgs = getArgument()

val isWebViewPageLoading = MutableLiveData(false)

return with(theme) {
constraint(
size = WidgetSize.AsParent
) {
val webViewConstraintItem = +webView(
size = WidgetSize.AsParent,
isJavaScriptEnabled = true,
targetUrl = inputArgs.targetUrl,
isWebPageLoading = isWebViewPageLoading
)

val progressVisibilityConstraintItem = +visibility(
child = progressBar(
size = WidgetSize.WrapContent
),
showed = isWebViewPageLoading
)

constraints {
webViewConstraintItem leftRightToLeftRight root
webViewConstraintItem topToTop root.safeArea

progressVisibilityConstraintItem topToTop root
progressVisibilityConstraintItem centerXToCenterX root
}
}
}
}

@Parcelize
data class WebViewArgs(
val targetUrl: String
) : Parcelable

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

package com.icerockdev.library.universal

import com.icerockdev.library.MR
import dev.icerock.moko.fields.FormField
import dev.icerock.moko.fields.liveBlock
import dev.icerock.moko.mvvm.dispatcher.EventsDispatcher
Expand Down Expand Up @@ -41,6 +40,7 @@ class LoginScreen(
private val theme: Theme,
private val mainRoute: Route<Unit>,
private val registerRoute: RouteWithResult<Unit, String>,
private val infoWebViewRoute: Route<String>,
private val loginViewModelFactory: (EventsDispatcher<LoginViewModel.EventsListener>) -> LoginViewModel
) : WidgetScreen<Args.Empty>(), NavigationItem, LoginViewModel.EventsListener {

Expand All @@ -61,8 +61,8 @@ class LoginScreen(

constraint(size = WidgetSize.AsParent) {
val logoImage = +image(
size = WidgetSize.Const(SizeSpec.WrapContent, SizeSpec.WrapContent),
image = const(Image.resource(MR.images.logo)),
size = WidgetSize.AspectByWidth(width = SizeSpec.Exact(300f), aspectRatio = 1.49f),
image = const(Image.network("https://html5box.com/html5lightbox/images/mountain.jpg")),
scaleType = ImageWidget.ScaleType.FIT
)

Expand All @@ -84,10 +84,15 @@ class LoginScreen(
content = ButtonWidget.Content.Text(Value.data("Login".desc())),
onTap = viewModel::onLoginPressed
)
val showInfoButton = +button(
size = WidgetSize.Const(SizeSpec.AsParent, SizeSpec.Exact(50f)),
content = ButtonWidget.Content.Text(Value.data("Show info".desc())),
onTap = viewModel::onShowInfoPressed
)

val registerButton = +button(
id = Id.RegistrationButtonId,
size = WidgetSize.Const(SizeSpec.WrapContent, SizeSpec.Exact(40f)),
size = WidgetSize.Const(SizeSpec.Exact(300f), SizeSpec.WrapContent),
content = ButtonWidget.Content.Text(Value.data("Registration".desc())),
onTap = viewModel::onRegistrationPressed
)
Expand All @@ -107,7 +112,10 @@ class LoginScreen(
loginButton topToBottom passwordInput
loginButton leftRightToLeftRight root

registerButton topToBottom loginButton
showInfoButton topToBottom loginButton
showInfoButton leftRightToLeftRight root

registerButton topToBottom showInfoButton
registerButton rightToRight root

// logo image height must be automatic ?
Expand All @@ -130,12 +138,17 @@ class LoginScreen(
}

override fun routeToMain() {
mainRoute.route(this)
mainRoute.route()
}

override fun routeToRegistration() {
registerRoute.route(this, registerHandler)
}

override fun routeToWebViewInfo() {
infoWebViewRoute.route("https://icerockdev.com/")
}

}

class LoginViewModel(
Expand All @@ -148,12 +161,17 @@ class LoginViewModel(
eventsDispatcher.dispatchEvent { routeToMain() }
}

fun onShowInfoPressed() {
eventsDispatcher.dispatchEvent { routeToWebViewInfo() }
}

fun onRegistrationPressed() {
eventsDispatcher.dispatchEvent { routeToRegistration() }
}

interface EventsListener {
fun routeToMain()
fun routeToRegistration()
fun routeToWebViewInfo()
}
}
Loading

0 comments on commit 5ad5080

Please sign in to comment.