Skip to content

Commit

Permalink
Merge pull request #318 from icerockdev/develop
Browse files Browse the repository at this point in the history
Release 0.2.4
  • Loading branch information
Alex009 authored May 13, 2023
2 parents 4017a8f + 1af37df commit c45f0ed
Show file tree
Hide file tree
Showing 19 changed files with 173 additions and 107 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,15 @@ allprojects {
project build.gradle
```groovy
dependencies {
commonMainApi("dev.icerock.moko:widgets:0.2.2")
commonMainApi("dev.icerock.moko:widgets-bottomsheet:0.2.2") // show bottom sheets
commonMainApi("dev.icerock.moko:widgets-collection:0.2.2") // collection widget
commonMainApi("dev.icerock.moko:widgets-datetime-picker:0.2.2") // show datepicker
commonMainApi("dev.icerock.moko:widgets-image-network:0.2.2") // images with load from url
commonMainApi("dev.icerock.moko:widgets-sms:0.2.2") // input with sms autofill
commonMainApi("dev.icerock.moko:widgets-media:0.2.2") // moko-media integration
commonMainApi("dev.icerock.moko:widgets-permissions:0.2.2") // moko-permissions integration
commonMainApi("dev.icerock.moko:widgets:0.2.4")
commonMainApi("dev.icerock.moko:widgets-bottomsheet:0.2.4") // show bottom sheets
commonMainApi("dev.icerock.moko:widgets-collection:0.2.4") // collection widget
commonMainApi("dev.icerock.moko:widgets-datetime-picker:0.2.4") // show datepicker
commonMainApi("dev.icerock.moko:widgets-image-network:0.2.4") // images with load from url
commonMainApi("dev.icerock.moko:widgets-sms:0.2.4") // input with sms autofill
commonMainApi("dev.icerock.moko:widgets-media:0.2.4") // moko-media integration
commonMainApi("dev.icerock.moko:widgets-permissions:0.2.4") // moko-permissions integration
}
```

Expand All @@ -230,7 +230,7 @@ buildscript {
}
dependencies {
classpath "dev.icerock.moko.widgets:gradle-plugin:0.2.2"
classpath "dev.icerock.moko.widgets:gradle-plugin:0.2.4"
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]
kotlinVersion = "1.8.10"

mokoWidgetsVersion = "0.2.3"
mokoWidgetsVersion = "0.2.4"
mokoResourcesVersion = "0.21.2"
mokoMvvmVersion = "0.16.0"
mokoFieldsVersion = "0.12.0"
Expand Down
2 changes: 1 addition & 1 deletion moko-widgets-bottomsheet.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = 'moko-widgets-bottomsheet'
spec.version = '0.2.2'
spec.version = '0.2.4'
spec.homepage = 'https://github.com/icerockdev/moko-widgets'
spec.source = { :git => "https://github.com/icerockdev/moko-widgets.git", :tag => "release/#{spec.version}" }
spec.authors = 'IceRock Development'
Expand Down
2 changes: 1 addition & 1 deletion moko-widgets-collection.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = 'moko-widgets-collection'
spec.version = '0.2.2'
spec.version = '0.2.4'
spec.homepage = 'https://github.com/icerockdev/moko-widgets'
spec.source = { :git => "https://github.com/icerockdev/moko-widgets.git", :tag => "release/#{spec.version}" }
spec.authors = 'IceRock Development'
Expand Down
2 changes: 1 addition & 1 deletion moko-widgets-datetime-picker.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = 'moko-widgets-datetime-picker'
spec.version = '0.2.2'
spec.version = '0.2.4'
spec.homepage = 'https://github.com/icerockdev/moko-widgets'
spec.source = { :git => "https://github.com/icerockdev/moko-widgets.git", :tag => "release/#{spec.version}" }
spec.authors = 'IceRock Development'
Expand Down
2 changes: 1 addition & 1 deletion moko-widgets-image-network.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = 'moko-widgets-image-network'
spec.version = '0.2.2'
spec.version = '0.2.4'
spec.homepage = 'https://github.com/icerockdev/moko-widgets'
spec.source = { :git => "https://github.com/icerockdev/moko-widgets.git", :tag => "release/#{spec.version}" }
spec.authors = 'IceRock Development'
Expand Down
4 changes: 2 additions & 2 deletions widgets/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ kotlin {
this as org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget

compilations.getByName("main") {
val pluralizedString by cinterops.creating {
defFile(project.file("src/iosMain/def/objcAddtition.def"))
val objcAddition by cinterops.creating {
defFile(project.file("src/iosMain/def/objcAddition.def"))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ void setAssociatedObject(id object, id value) {
return objc_setAssociatedObject(object, &kAssociatedObjectKey, value, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

void setAssociatedObjectWithKey(id object, NSValue* key, id value) {
return objc_setAssociatedObject(object, key.pointerValue, value, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

NSArray* cgColors(NSArray<UIColor*>* uiColors) {
NSMutableArray* result = [NSMutableArray arrayWithCapacity: uiColors.count];
for(int i = 0;i < uiColors.count;i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ import dev.icerock.moko.widgets.core.style.view.MarginValues
import dev.icerock.moko.widgets.core.style.view.PaddingValues
import dev.icerock.moko.widgets.core.style.view.WidgetSize
import dev.icerock.moko.widgets.core.utils.Edges
import dev.icerock.moko.widgets.core.utils.UIViewWithIdentifier
import dev.icerock.moko.widgets.core.utils.applyBackgroundIfNeeded
import dev.icerock.moko.widgets.core.utils.applySizeToChild
import dev.icerock.moko.widgets.core.utils.identifier
import dev.icerock.moko.widgets.core.widget.CardWidget
import kotlinx.cinterop.ExportObjCClass
import kotlinx.cinterop.readValue
import platform.CoreGraphics.CGFloat
import platform.CoreGraphics.CGRectZero
import platform.CoreGraphics.CGSizeMake
import platform.UIKit.UIColor
import platform.UIKit.UIView
Expand All @@ -31,6 +32,10 @@ import platform.UIKit.leadingAnchor
import platform.UIKit.topAnchor
import platform.UIKit.trailingAnchor
import platform.UIKit.translatesAutoresizingMaskIntoConstraints

@ExportObjCClass
private class CardViewContainer : UIView(frame = CGRectZero.readValue())

@Suppress("MagicNumber")
actual class CardViewFactory actual constructor(
private val padding: PaddingValues?,
Expand All @@ -46,15 +51,13 @@ actual class CardViewFactory actual constructor(

val viewController: UIViewController = viewFactoryContext

val root = UIViewWithIdentifier().apply {
val root = CardViewContainer().apply {
translatesAutoresizingMaskIntoConstraints = false
applyBackgroundIfNeeded(background)

layer.cornerRadius = background?.cornerRadius?.toDouble() ?: 0.0
clipsToBounds = true
backgroundColor = UIColor.whiteColor

accessibilityIdentifier = widget.identifier()
}

val childViewBundle = widget.child.buildView(viewController)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import dev.icerock.moko.widgets.core.widget.Constraint
import dev.icerock.moko.widgets.core.widget.ConstraintItem
import dev.icerock.moko.widgets.core.widget.ConstraintWidget
import dev.icerock.moko.widgets.core.widget.ConstraintsApi
import kotlinx.cinterop.ExportObjCClass
import kotlinx.cinterop.readValue
import platform.CoreGraphics.CGFloat
import platform.CoreGraphics.CGRectZero
Expand All @@ -37,6 +38,9 @@ import platform.UIKit.safeAreaLayoutGuide
import platform.UIKit.topAnchor
import platform.UIKit.translatesAutoresizingMaskIntoConstraints

@ExportObjCClass
private class ConstraintViewContainer : UIView(frame = CGRectZero.readValue())

actual class ConstraintViewFactory actual constructor(
private val background: Background<out Fill>?,
private val padding: PaddingValues?,
Expand All @@ -48,7 +52,7 @@ actual class ConstraintViewFactory actual constructor(
size: WS,
viewFactoryContext: ViewFactoryContext,
): ViewBundle<WS> {
val container = UIView(frame = CGRectZero.readValue()).apply {
val container = ConstraintViewContainer().apply {
translatesAutoresizingMaskIntoConstraints = false

applyBackgroundIfNeeded(background)
Expand Down Expand Up @@ -205,9 +209,11 @@ class AutoLayoutConstraintsApi(
override fun offset(points: Int) {
it.constant = const + points
if (applyExtraMargins != null) {
applyAdditionalMargins(firstItem.widget,
applyAdditionalMargins(
firstItem.widget,
points.toFloat(),
applyExtraMargins)
applyExtraMargins
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ import dev.icerock.moko.widgets.core.style.view.MarginValues
import dev.icerock.moko.widgets.core.style.view.PaddingValues
import dev.icerock.moko.widgets.core.style.view.WidgetSize
import dev.icerock.moko.widgets.core.utils.Edges
import dev.icerock.moko.widgets.core.utils.UIViewWithIdentifier
import dev.icerock.moko.widgets.core.utils.applyBackgroundIfNeeded
import dev.icerock.moko.widgets.core.utils.applySizeToChild
import dev.icerock.moko.widgets.core.utils.identifier
import dev.icerock.moko.widgets.core.widget.ContainerWidget
import kotlinx.cinterop.ExportObjCClass
import kotlinx.cinterop.readValue
import platform.CoreGraphics.CGFloat
import platform.CoreGraphics.CGRectZero
import platform.UIKit.UIView
import platform.UIKit.UIViewController
import platform.UIKit.addSubview
import platform.UIKit.bottomAnchor
Expand All @@ -30,6 +32,9 @@ import platform.UIKit.topAnchor
import platform.UIKit.trailingAnchor
import platform.UIKit.translatesAutoresizingMaskIntoConstraints

@ExportObjCClass
private class ContainerView : UIView(frame = CGRectZero.readValue())

actual class ContainerViewFactory actual constructor(
private val padding: PaddingValues?,
private val margins: MarginValues?,
Expand All @@ -43,11 +48,9 @@ actual class ContainerViewFactory actual constructor(
): ViewBundle<WS> {
val viewController: UIViewController = viewFactoryContext

val root = UIViewWithIdentifier().apply {
val root = ContainerView().apply {
translatesAutoresizingMaskIntoConstraints = false
applyBackgroundIfNeeded(background)

accessibilityIdentifier = widget.identifier()
}

widget.children.forEach { (childWidget, childAlignment) ->
Expand All @@ -73,6 +76,7 @@ actual class ContainerViewFactory actual constructor(
childView.centerYAnchor.constraintEqualToAnchor(root.centerYAnchor).active =
true
}

Alignment.LEFT -> {
childView.leadingAnchor.constraintEqualToAnchor(
anchor = root.leadingAnchor,
Expand All @@ -81,6 +85,7 @@ actual class ContainerViewFactory actual constructor(
childView.centerYAnchor.constraintEqualToAnchor(root.centerYAnchor).active =
true
}

Alignment.RIGHT -> {
childView.trailingAnchor.constraintEqualToAnchor(
anchor = root.trailingAnchor,
Expand All @@ -89,6 +94,7 @@ actual class ContainerViewFactory actual constructor(
childView.centerYAnchor.constraintEqualToAnchor(root.centerYAnchor).active =
true
}

Alignment.TOP -> {
childView.topAnchor.constraintEqualToAnchor(
anchor = root.topAnchor,
Expand All @@ -97,6 +103,7 @@ actual class ContainerViewFactory actual constructor(
childView.centerXAnchor.constraintEqualToAnchor(root.centerXAnchor).active =
true
}

Alignment.BOTTOM -> {
childView.bottomAnchor.constraintEqualToAnchor(
anchor = root.bottomAnchor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import dev.icerock.moko.widgets.core.utils.Edges
import dev.icerock.moko.widgets.core.utils.applyBackgroundIfNeeded
import dev.icerock.moko.widgets.core.utils.applySize
import dev.icerock.moko.widgets.core.widget.LinearWidget
import kotlinx.cinterop.ExportObjCClass
import kotlinx.cinterop.readValue
import platform.CoreGraphics.CGFloat
import platform.CoreGraphics.CGRectZero
Expand All @@ -36,6 +37,9 @@ import platform.UIKit.trailingAnchor
import platform.UIKit.translatesAutoresizingMaskIntoConstraints
import platform.UIKit.widthAnchor

@ExportObjCClass
private class LinearViewContainer : UIView(frame = CGRectZero.readValue())

actual class LinearViewFactory actual constructor(
private val padding: PaddingValues?,
private val margins: MarginValues?,
Expand All @@ -49,7 +53,7 @@ actual class LinearViewFactory actual constructor(
): ViewBundle<WS> {
val viewController: UIViewController = viewFactoryContext

val container = UIView(frame = CGRectZero.readValue()).apply {
val container = LinearViewContainer().apply {
translatesAutoresizingMaskIntoConstraints = false
applyBackgroundIfNeeded(background)
}
Expand All @@ -61,6 +65,7 @@ actual class LinearViewFactory actual constructor(
viewController = viewController,
size = size
)

Orientation.VERTICAL -> layoutVertical(
root = container,
children = widget.children,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ import dev.icerock.moko.widgets.core.style.view.TextStyle
import dev.icerock.moko.widgets.core.style.view.WidgetSize
import dev.icerock.moko.widgets.core.utils.applyBackgroundIfNeeded
import dev.icerock.moko.widgets.core.utils.applyTextStyleIfNeeded
import dev.icerock.moko.widgets.core.utils.bind
import dev.icerock.moko.widgets.core.utils.setAssociatedObject
import dev.icerock.moko.widgets.core.widget.InputWidget
import kotlinx.cinterop.ObjCAction
import kotlinx.cinterop.cstr
import kotlinx.cinterop.readValue
import platform.CoreGraphics.CGRectZero
import platform.Foundation.NSNotification
Expand All @@ -42,8 +41,6 @@ import platform.UIKit.UITextViewTextDidEndEditingNotification
import platform.UIKit.clipsToBounds
import platform.UIKit.translatesAutoresizingMaskIntoConstraints
import platform.darwin.NSObject
import platform.objc.OBJC_ASSOCIATION_RETAIN_NONATOMIC
import platform.objc.objc_setAssociatedObject

actual class MultilineInputViewFactory actual constructor(
private val background: Background<Fill.Solid>?,
Expand Down Expand Up @@ -138,11 +135,10 @@ actual class MultilineInputViewFactory actual constructor(
}
}

objc_setAssociatedObject(
`object` = textView,
key = "textViewObserver".cstr,
value = observer,
policy = OBJC_ASSOCIATION_RETAIN_NONATOMIC
setAssociatedObject(
obj = textView,
key = "textViewObserver",
target = observer
)

return ViewBundle(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import dev.icerock.moko.mvvm.ResourceState
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.core.Widget
import dev.icerock.moko.widgets.core.style.background.Background
import dev.icerock.moko.widgets.core.style.background.Fill
import dev.icerock.moko.widgets.core.style.view.MarginValues
Expand All @@ -18,6 +19,7 @@ import dev.icerock.moko.widgets.core.utils.applyBackgroundIfNeeded
import dev.icerock.moko.widgets.core.utils.applySizeToChild
import dev.icerock.moko.widgets.core.utils.fillChildView
import dev.icerock.moko.widgets.core.widget.StatefulWidget
import kotlinx.cinterop.ExportObjCClass
import kotlinx.cinterop.readValue
import platform.CoreGraphics.CGFloat
import platform.CoreGraphics.CGRectZero
Expand All @@ -27,6 +29,9 @@ import platform.UIKit.addSubview
import platform.UIKit.hidden
import platform.UIKit.translatesAutoresizingMaskIntoConstraints

@ExportObjCClass
private class StatefulViewContainer : UIView(frame = CGRectZero.readValue())

actual class StatefulViewFactory actual constructor(
private val margins: MarginValues?,
private val padding: PaddingValues?,
Expand All @@ -40,18 +45,20 @@ actual class StatefulViewFactory actual constructor(
): ViewBundle<WS> {
val viewController: UIViewController = viewFactoryContext

val container = UIView(frame = CGRectZero.readValue()).apply {
val container = StatefulViewContainer().apply {
translatesAutoresizingMaskIntoConstraints = false

applyBackgroundIfNeeded(background)
}

listOf(
widget.dataWidget,
widget.emptyWidget,
widget.loadingWidget,
widget.errorWidget
).forEach { childWidget ->
val widgetStateMap: Map<Widget<*>, (ResourceState<*, *>) -> Boolean> = mapOf(
widget.dataWidget to { it is ResourceState.Success },
widget.emptyWidget to { it is ResourceState.Empty },
widget.loadingWidget to { it is ResourceState.Loading },
widget.errorWidget to { it is ResourceState.Failed }
)

widgetStateMap.forEach { (childWidget, isRelatedState) ->
val childViewBundle = childWidget.buildView(viewController)
val childView = childViewBundle.view
childView.translatesAutoresizingMaskIntoConstraints = false
Expand All @@ -72,12 +79,7 @@ actual class StatefulViewFactory actual constructor(
}

fun updateState(state: ResourceState<*, *>) {
childView.hidden = when (state) {
is ResourceState.Success -> childWidget == widget.dataWidget
is ResourceState.Empty -> childWidget == widget.emptyWidget
is ResourceState.Failed -> childWidget == widget.errorWidget
is ResourceState.Loading -> childWidget == widget.loadingWidget
}.not()
childView.hidden = isRelatedState(state).not()
}

updateState(widget.state.value)
Expand Down
Loading

0 comments on commit c45f0ed

Please sign in to comment.