Skip to content

Commit

Permalink
Merge pull request #64 from icerockdev/develop
Browse files Browse the repository at this point in the history
Release 0.1.0-dev-10
  • Loading branch information
Alex009 authored Feb 5, 2020
2 parents dced02d + bed483d commit f837600
Show file tree
Hide file tree
Showing 22 changed files with 608 additions and 206 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-9`. Dev version is not tested in production tasks yet, API can be changed and
Current version - `0.1.0-dev-10`. 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 @@ -216,6 +216,7 @@ val loginScreen = Theme(baseTheme) {
- 0.1.0-dev-7
- 0.1.0-dev-8
- 0.1.0-dev-9
- 0.1.0-dev-10

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

Expand All @@ -248,7 +249,7 @@ buildscript {
}
dependencies {
classpath "dev.icerock.moko.widgets:gradle-plugin:0.1.0-dev-9"
classpath "dev.icerock.moko.widgets:gradle-plugin:0.1.0-dev-10"
}
}
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ object Versions {
}

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

object Plugins {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import dev.icerock.moko.mvvm.viewmodel.ViewModel
import dev.icerock.moko.resources.desc.StringDesc
import dev.icerock.moko.resources.desc.desc
import dev.icerock.moko.widgets.ButtonWidget
import dev.icerock.moko.widgets.TabsWidget
import dev.icerock.moko.widgets.button
import dev.icerock.moko.widgets.container
import dev.icerock.moko.widgets.core.Theme
Expand All @@ -22,6 +21,7 @@ import dev.icerock.moko.widgets.flatAlert
import dev.icerock.moko.widgets.linear
import dev.icerock.moko.widgets.progressBar
import dev.icerock.moko.widgets.stateful
import dev.icerock.moko.widgets.style.background.Orientation
import dev.icerock.moko.widgets.style.view.SizeSpec
import dev.icerock.moko.widgets.style.view.WidgetSize
import dev.icerock.moko.widgets.tabs
Expand All @@ -35,11 +35,21 @@ open class StateScreen(
fun createWidget(): Widget<WidgetSize.Const<SizeSpec.AsParent, SizeSpec.AsParent>> {
return with(theme) {
linear(size = WidgetSize.AsParent) {
+button(
size = WidgetSize.WrapContent,
content = ButtonWidget.Content.Text(Value.data("change state".desc())),
onTap = viewModel::onChangeStatePressed
)
+linear(
size = WidgetSize.WidthAsParentHeightWrapContent,
orientation = Orientation.HORIZONTAL
) {
+button(
size = WidgetSize.WrapContent,
content = ButtonWidget.Content.Text(Value.data("change state".desc())),
onTap = viewModel::onChangeStatePressed
)
+button(
size = WidgetSize.WrapContent,
content = ButtonWidget.Content.Text(Value.data("just log button".desc())),
onTap = { println("pressed!") }
)
}
+stateful(
size = WidgetSize.AsParent,
state = viewModel.state,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import com.icerockdev.library.sample.StateViewModel
import com.icerockdev.library.sample.UsersScreen
import com.icerockdev.library.sample.UsersViewModel
import dev.icerock.moko.widgets.CollectionWidget
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.screen.Args
Expand All @@ -34,57 +35,70 @@ class WidgetsScreen(

override fun createContentWidget(): Widget<WidgetSize.Const<SizeSpec.AsParent, SizeSpec.AsParent>> {
return with(theme) {
tabs(size = WidgetSize.AsParent) {
tab(
title = const("P#2"),
body = SocialProfileScreen(
theme = theme, //AppTheme.socialWidgetScope,
viewModel = SocialProfileViewModel()
).createWidget()
)
tab(
title = const("P#4"),
body = CryptoProfileScreen(
theme = theme, //AppTheme.cryptoWidgetScope,
viewModel = CryptoProfileViewModel()
).createWidget()
)
tab(
title = const("P#1"),
body = SocialProfileScreen(
theme = theme,
viewModel = SocialProfileViewModel()
).createWidget()
)
tab(
title = const("P#3"),
body = McommerceProfileScreen(
theme = theme, //AppTheme.mcommerceWidgetScope,
viewModel = McommerceProfileViewModel()
).createWidget()
)
tab(
title = const("D"),
body = StateScreen(
theme = theme,
viewModel = StateViewModel()
).createWidget()
)
tab(
title = const("P"),
body = PostsScreen(
theme = theme,
viewModel = PostsViewModel(),
collectionCategory = postsCollectionCategory
).createWidget()
)
tab(
title = const("U"),
body = UsersScreen(
theme = theme,
viewModel = UsersViewModel(sharedFactory.usersUnitsFactory)
).createWidget()
)
constraint(size = WidgetSize.AsParent) {
val tabs = +tabs(
size = WidgetSize.Const(
width = SizeSpec.MatchConstraint,
height = SizeSpec.MatchConstraint
)
) {
tab(
title = const("P#2"),
body = SocialProfileScreen(
theme = theme, //AppTheme.socialWidgetScope,
viewModel = SocialProfileViewModel()
).createWidget()
)
tab(
title = const("P#4"),
body = CryptoProfileScreen(
theme = theme, //AppTheme.cryptoWidgetScope,
viewModel = CryptoProfileViewModel()
).createWidget()
)
tab(
title = const("P#1"),
body = SocialProfileScreen(
theme = theme,
viewModel = SocialProfileViewModel()
).createWidget()
)
tab(
title = const("P#3"),
body = McommerceProfileScreen(
theme = theme, //AppTheme.mcommerceWidgetScope,
viewModel = McommerceProfileViewModel()
).createWidget()
)
tab(
title = const("D"),
body = StateScreen(
theme = theme,
viewModel = StateViewModel()
).createWidget()
)
tab(
title = const("P"),
body = PostsScreen(
theme = theme,
viewModel = PostsViewModel(),
collectionCategory = postsCollectionCategory
).createWidget()
)
tab(
title = const("U"),
body = UsersScreen(
theme = theme,
viewModel = UsersViewModel(sharedFactory.usersUnitsFactory)
).createWidget()
)
}

constraints {
tabs topToTop root.safeArea
tabs bottomToBottom root.safeArea
tabs leftRightToLeftRight root
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import dev.icerock.moko.widgets.core.ViewBundle
import dev.icerock.moko.widgets.core.ViewFactory
import dev.icerock.moko.widgets.core.ViewFactoryContext
import dev.icerock.moko.widgets.style.view.WidgetSize
import dev.icerock.moko.widgets.utils.androidId
import dev.icerock.moko.widgets.utils.bindNotNull

actual class CheckboxSwitchViewFactory actual constructor(
Expand All @@ -27,7 +28,9 @@ actual class CheckboxSwitchViewFactory actual constructor(
val context = viewFactoryContext.context
val lifecycleOwner = viewFactoryContext.lifecycleOwner

val checkbox = CheckBox(context)
val checkbox = CheckBox(context).apply {
id = widget.id.androidId
}

val drawable = StateListDrawable().apply {
addState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package dev.icerock.moko.widgets.factory

import android.view.ViewGroup
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.ViewCompat
import dev.icerock.moko.widgets.Constraint
import dev.icerock.moko.widgets.ConstraintItem
import dev.icerock.moko.widgets.ConstraintWidget
Expand Down Expand Up @@ -52,10 +53,9 @@ actual class ConstraintViewFactory actual constructor(
constraintLayout.addView(viewBundle)

// check id and autoassign if needed
// TODO something can be wrong with autoassign?
viewBundle.view.run {
if (id == View.NO_ID) {
id = childWidget.hashCode()
id = ViewCompat.generateViewId()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import dev.icerock.moko.widgets.style.view.PaddingValues
import dev.icerock.moko.widgets.style.view.TextHorizontalAlignment
import dev.icerock.moko.widgets.style.view.TextStyle
import dev.icerock.moko.widgets.style.view.WidgetSize
import dev.icerock.moko.widgets.utils.androidId
import dev.icerock.moko.widgets.utils.bind
import dev.icerock.moko.widgets.utils.dp
import dev.icerock.moko.widgets.utils.sp
Expand Down Expand Up @@ -65,7 +66,7 @@ actual class FloatingLabelInputViewFactory actual constructor(
textInputLayout.applyPaddingIfNeeded(padding)

val editText = TextInputEditText(context).apply {
id = widget.id::javaClass.name.hashCode()
id = widget.id.androidId

layoutParams = LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import dev.icerock.moko.widgets.style.ext.toStaggeredGridLayoutManager
import dev.icerock.moko.widgets.style.view.MarginValues
import dev.icerock.moko.widgets.style.view.PaddingValues
import dev.icerock.moko.widgets.style.view.WidgetSize
import dev.icerock.moko.widgets.utils.androidId
import dev.icerock.moko.widgets.utils.bind
import dev.icerock.moko.widgets.view.UnitItemDecorator

Expand Down Expand Up @@ -51,7 +52,7 @@ actual class SystemCollectionViewFactory actual constructor(
)
adapter = unitsAdapter

id = widget.id::javaClass.name.hashCode()
id = widget.id.androidId

applyPaddingIfNeeded(padding)
applyBackgroundIfNeeded(this@SystemCollectionViewFactory.background)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import dev.icerock.moko.widgets.style.applyTextStyleIfNeeded
import dev.icerock.moko.widgets.style.background.Background
import dev.icerock.moko.widgets.style.ext.getGravityForTextAlignment
import dev.icerock.moko.widgets.style.view.*
import dev.icerock.moko.widgets.utils.androidId
import dev.icerock.moko.widgets.utils.bind
import dev.icerock.moko.widgets.utils.dp

Expand Down Expand Up @@ -51,7 +52,7 @@ actual class SystemInputViewFactory actual constructor(
applyBackgroundIfNeeded(this@SystemInputViewFactory.background)
applyPaddingIfNeeded(padding)

id = widget.id::javaClass.name.hashCode()
id = widget.id.androidId

layoutParams = LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import dev.icerock.moko.widgets.style.background.Background
import dev.icerock.moko.widgets.style.view.MarginValues
import dev.icerock.moko.widgets.style.view.PaddingValues
import dev.icerock.moko.widgets.style.view.WidgetSize
import dev.icerock.moko.widgets.utils.androidId
import dev.icerock.moko.widgets.utils.bind

actual class SystemListViewFactory actual constructor(
Expand Down Expand Up @@ -56,7 +57,7 @@ actual class SystemListViewFactory actual constructor(

applyPaddingIfNeeded(padding)

id = widget.id::javaClass.name.hashCode()
id = widget.id.androidId
}

val resultView: View = if (haveSwipeRefreshListener) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import dev.icerock.moko.widgets.style.ext.toPlatformSize
import dev.icerock.moko.widgets.style.view.MarginValues
import dev.icerock.moko.widgets.style.view.PaddingValues
import dev.icerock.moko.widgets.style.view.WidgetSize
import dev.icerock.moko.widgets.utils.androidId

actual class SystemScrollViewFactory actual constructor(
private val background: Background?,
Expand All @@ -38,7 +39,7 @@ actual class SystemScrollViewFactory actual constructor(
applyBackgroundIfNeeded(this@SystemScrollViewFactory.background)
applyPaddingIfNeeded(padding)

id = widget.id::javaClass.name.hashCode()
id = widget.id.androidId
}

val childBundle = widget.child.buildView(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import dev.icerock.moko.widgets.style.view.MarginValues
import dev.icerock.moko.widgets.style.view.PaddingValues
import dev.icerock.moko.widgets.style.view.TextStyle
import dev.icerock.moko.widgets.style.view.WidgetSize
import dev.icerock.moko.widgets.utils.androidId
import dev.icerock.moko.widgets.utils.bind
import dev.icerock.moko.widgets.utils.dp

Expand Down Expand Up @@ -83,6 +84,8 @@ actual class SystemSingleChoiceViewFactory actual constructor(
underlineColor?.also {
ViewCompat.setBackgroundTintList(this, ColorStateList.valueOf(it.argb.toInt()))
}

id = widget.id.androidId
}

textInputLayout.addView(editText)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import dev.icerock.moko.widgets.style.background.Background
import dev.icerock.moko.widgets.style.background.buildBackground
import dev.icerock.moko.widgets.style.view.MarginValues
import dev.icerock.moko.widgets.style.view.WidgetSize
import dev.icerock.moko.widgets.utils.androidId
import dev.icerock.moko.widgets.utils.bindNotNull

actual class SystemSwitchViewFactory actual constructor(
Expand All @@ -32,6 +33,8 @@ actual class SystemSwitchViewFactory actual constructor(
val context = viewFactoryContext.androidContext

val switch = Switch(context).apply {
id = widget.id.androidId

switchColor?.also { colorStyle ->
val thumbStates = ColorStateList(
arrayOf(
Expand Down
Loading

0 comments on commit f837600

Please sign in to comment.