-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #156 from icerockdev/develop
Release 0.1.0-dev-14
- Loading branch information
Showing
15 changed files
with
356 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
sample/mpp-library/src/commonMain/kotlin/dev/icerock/moko/widgets/sample/TabsSampleScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
/* | ||
* Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package dev.icerock.moko.widgets.sample | ||
|
||
import com.icerockdev.library.units.UserUnitWidget | ||
import dev.icerock.moko.graphics.Color | ||
import dev.icerock.moko.resources.desc.desc | ||
import dev.icerock.moko.units.TableUnitItem | ||
import dev.icerock.moko.widgets.ContainerWidget | ||
import dev.icerock.moko.widgets.ListWidget | ||
import dev.icerock.moko.widgets.TabsWidget | ||
import dev.icerock.moko.widgets.constraint | ||
import dev.icerock.moko.widgets.container | ||
import dev.icerock.moko.widgets.core.Theme | ||
import dev.icerock.moko.widgets.core.Widget | ||
import dev.icerock.moko.widgets.factory.ContainerViewFactory | ||
import dev.icerock.moko.widgets.factory.SystemTabsViewFactory | ||
import dev.icerock.moko.widgets.linear | ||
import dev.icerock.moko.widgets.list | ||
import dev.icerock.moko.widgets.screen.Args | ||
import dev.icerock.moko.widgets.screen.WidgetScreen | ||
import dev.icerock.moko.widgets.screen.navigation.NavigationBar | ||
import dev.icerock.moko.widgets.screen.navigation.NavigationItem | ||
import dev.icerock.moko.widgets.style.background.Background | ||
import dev.icerock.moko.widgets.style.background.Direction | ||
import dev.icerock.moko.widgets.style.background.Fill | ||
import dev.icerock.moko.widgets.style.state.SelectableState | ||
import dev.icerock.moko.widgets.style.view.Colors | ||
import dev.icerock.moko.widgets.style.view.PaddingValues | ||
import dev.icerock.moko.widgets.style.view.SizeSpec | ||
import dev.icerock.moko.widgets.style.view.TextStyle | ||
import dev.icerock.moko.widgets.style.view.WidgetSize | ||
import dev.icerock.moko.widgets.tabs | ||
import dev.icerock.moko.widgets.utils.platformSpecific | ||
|
||
class TabsSampleScreen( | ||
private val theme: Theme | ||
) : WidgetScreen<Args.Empty>(), NavigationItem { | ||
|
||
override val navigationBar: NavigationBar = NavigationBar.Normal( | ||
title = "Tabs sample".desc(), | ||
styles = NavigationBar.Styles( | ||
backgroundColor = backgroundColor, | ||
tintColor = tintColor, | ||
textStyle = TextStyle( | ||
color = textColor | ||
), | ||
isShadowEnabled = false | ||
) | ||
) | ||
|
||
override fun createContentWidget(): Widget<WidgetSize.Const<SizeSpec.AsParent, SizeSpec.AsParent>> { | ||
return with(theme) { | ||
constraint(size = WidgetSize.AsParent) { | ||
val tabs = +tabs(size = WidgetSize.Const(SizeSpec.MatchConstraint, SizeSpec.MatchConstraint)) { | ||
tab( | ||
title = const("Active".desc()), | ||
body = buildContent() | ||
) | ||
|
||
tab( | ||
title = const("Done".desc()), | ||
body = buildContent() | ||
) | ||
} | ||
|
||
constraints { | ||
tabs topToTop root.safeArea | ||
tabs leftRightToLeftRight root | ||
tabs bottomToBottom root.safeArea | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun Theme.buildContent() = { | ||
val items = List(20) { | ||
UserUnitWidget.TableUnitItem( | ||
theme = this@buildContent, | ||
itemId = it.toLong(), | ||
data = UserUnitWidget.Data( | ||
name = "item $it", | ||
avatarUrl = "https://i.imgur.com/cVDadwb.png", | ||
onClick = {} | ||
) | ||
) as TableUnitItem | ||
} | ||
|
||
linear(size = WidgetSize.AsParent) { | ||
+container( | ||
size = WidgetSize.Const( | ||
width = SizeSpec.AsParent, | ||
height = SizeSpec.Exact(platformSpecific(android = 4f, ios = 2f)) | ||
) | ||
) {} | ||
|
||
+list( | ||
size = WidgetSize.AsParent, | ||
id = Ids.List, | ||
items = const(items) | ||
) | ||
} | ||
}() | ||
|
||
object Ids { | ||
object List : ListWidget.Id | ||
} | ||
|
||
companion object { | ||
val tintColor = Color(0xD20C0AFF) | ||
val backgroundColor = Color(0xFFFFFFFF) | ||
val textColor = Color(0x151515FF) | ||
|
||
fun configureDefaultTheme(theme: Theme.Builder) = with(theme) { | ||
factory[TabsWidget.DefaultCategory] = SystemTabsViewFactory( | ||
tabsTintColor = tintColor, | ||
tabsBackground = Background( | ||
fill = Fill.Solid(backgroundColor) | ||
), | ||
tabsPadding = platformSpecific( | ||
android = null, | ||
ios = PaddingValues(start = 16f, end = 16f, bottom = 16f) | ||
), | ||
titleColor = SelectableState( | ||
selected = platformSpecific(android = null, ios = Colors.white), | ||
unselected = null | ||
) | ||
) | ||
factory[ContainerWidget.DefaultCategory] = ContainerViewFactory( | ||
background = Background( | ||
fill = Fill.Gradient( | ||
colors = listOf(Color(0x00000000), Color(0x00000010)), | ||
direction = Direction.BOTTOM_TOP | ||
) | ||
) | ||
) | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
widgets/src/androidMain/kotlin/dev/icerock/moko/widgets/screen/dialPhoneExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package dev.icerock.moko.widgets.screen | ||
|
||
import android.content.Intent | ||
import android.net.Uri | ||
|
||
actual fun Screen<*>.dialPhone(phone: String) { | ||
val context = context ?: return | ||
|
||
val intent = Intent(Intent.ACTION_DIAL, Uri.parse("tel:$phone")) | ||
if (intent.resolveActivity(context.packageManager) == null) { | ||
println("activity for $intent not found") | ||
return | ||
} | ||
|
||
startActivity(intent) | ||
} |
33 changes: 33 additions & 0 deletions
33
widgets/src/androidMain/kotlin/dev/icerock/moko/widgets/screen/sendEmailExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package dev.icerock.moko.widgets.screen | ||
|
||
import android.content.Intent | ||
import android.net.Uri | ||
|
||
actual fun Screen<*>.sendEmail( | ||
email: String, | ||
subject: String, | ||
body: String | ||
) { | ||
val context = context ?: return | ||
|
||
val intent = Intent( | ||
Intent.ACTION_SENDTO, | ||
Uri.fromParts( | ||
"mailto", | ||
email, | ||
null | ||
) | ||
) | ||
intent.putExtra(Intent.EXTRA_SUBJECT, subject) | ||
intent.putExtra(Intent.EXTRA_TEXT, body) | ||
if (intent.resolveActivity(context.packageManager) == null) { | ||
println("email clients not found") | ||
return | ||
} | ||
|
||
startActivity(Intent.createChooser(intent, email)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
widgets/src/androidMain/kotlin/dev/icerock/moko/widgets/style/NavigationBarStyles.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2020 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package dev.icerock.moko.widgets.style | ||
|
||
import android.content.Context | ||
import androidx.appcompat.widget.Toolbar | ||
import androidx.core.graphics.drawable.DrawableCompat | ||
import androidx.core.view.ViewCompat | ||
import dev.icerock.moko.widgets.screen.navigation.NavigationBar | ||
import dev.icerock.moko.widgets.utils.ThemeAttrs | ||
import dev.icerock.moko.widgets.utils.dp | ||
|
||
|
||
fun NavigationBar.Styles.apply( | ||
toolbar: Toolbar, | ||
context: Context | ||
) { | ||
val bgColor = backgroundColor?.argb?.toInt() | ||
?: ThemeAttrs.getPrimaryColor(context) | ||
|
||
toolbar.setBackgroundColor(bgColor) | ||
|
||
val fallbackTintColor = ThemeAttrs.getControlNormalColor(context) | ||
|
||
val tintColor = tintColor?.argb?.toInt() ?: fallbackTintColor | ||
|
||
toolbar.setTitleTextColor(tintColor) | ||
toolbar.overflowIcon?.also { DrawableCompat.setTint(it, tintColor) } | ||
|
||
val textColor = textStyle?.color?.argb?.toInt() ?: fallbackTintColor | ||
toolbar.setTitleTextColor(textColor) | ||
|
||
if (isShadowEnabled == false) { | ||
ViewCompat.setElevation(toolbar, 0f) | ||
} else { | ||
// 4 points https://material.io/design/environment/elevation.html#elevation-shadows-elevation-android | ||
ViewCompat.setElevation(toolbar, 4f.dp(context)) | ||
} | ||
} |
Oops, something went wrong.