Status/Nav Bar padding Fixes,migrate to IR Compiler and various updates

This commit is contained in:
shabinder 2021-04-14 23:07:02 +05:30
parent 2034616aeb
commit c25837845e
10 changed files with 105 additions and 62 deletions

View File

@ -49,7 +49,7 @@ android {
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
} }
} }
kotlinOptions.useIR = true
compileOptions { compileOptions {
// Flag to enable support for the new language APIs // Flag to enable support for the new language APIs
//coreLibraryDesugaringEnabled = true //coreLibraryDesugaringEnabled = true
@ -68,6 +68,7 @@ android {
packagingOptions { packagingOptions {
exclude("META-INF/*") exclude("META-INF/*")
} }
buildToolsVersion = "30.0.3"
/*buildFeatures { /*buildFeatures {
compose = true compose = true
} }
@ -90,12 +91,14 @@ dependencies {
implementation(Koin.android) implementation(Koin.android)
implementation(Koin.compose) implementation(Koin.compose)
implementation("com.google.accompanist:accompanist-insets:0.7.1")
//DECOMPOSE //DECOMPOSE
implementation(Decompose.decompose) implementation(Decompose.decompose)
implementation(Decompose.extensionsCompose) implementation(Decompose.extensionsCompose)
//Firebase //Firebase
implementation(platform("com.google.firebase:firebase-bom:26.5.0")) implementation(platform("com.google.firebase:firebase-bom:27.0.0"))
implementation("com.google.firebase:firebase-analytics-ktx") implementation("com.google.firebase:firebase-analytics-ktx")
implementation("com.google.firebase:firebase-crashlytics-ktx") implementation("com.google.firebase:firebase-crashlytics-ktx")
implementation("com.google.firebase:firebase-perf-ktx") implementation("com.google.firebase:firebase-perf-ktx")
@ -129,16 +132,5 @@ dependencies {
androidTestImplementation(Androidx.expresso) androidTestImplementation(Androidx.expresso)
//Desugaring //Desugaring
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.1.1") coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.1.5")
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
freeCompilerArgs = listOf(
"-Xallow-jvm-ir-dependencies","-Xallow-unstable-dependencies",
"-Xskip-prerelease-check",
"-Xuse-experimental=kotlinx.coroutines.ExperimentalCoroutinesApi"
)
}
} }

View File

@ -37,6 +37,7 @@ import androidx.compose.material.icons.rounded.SystemSecurityUpdate
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalView import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.font.FontWeight
@ -49,6 +50,10 @@ import com.arkivanov.decompose.ComponentContext
import com.arkivanov.decompose.extensions.compose.jetbrains.rememberRootComponent import com.arkivanov.decompose.extensions.compose.jetbrains.rememberRootComponent
import com.arkivanov.mvikotlin.logging.store.LoggingStoreFactory import com.arkivanov.mvikotlin.logging.store.LoggingStoreFactory
import com.arkivanov.mvikotlin.main.store.DefaultStoreFactory import com.arkivanov.mvikotlin.main.store.DefaultStoreFactory
import com.google.accompanist.insets.ProvideWindowInsets
import com.google.accompanist.insets.navigationBarsPadding
import com.google.accompanist.insets.statusBarsHeight
import com.google.accompanist.insets.statusBarsPadding
import com.razorpay.Checkout import com.razorpay.Checkout
import com.razorpay.PaymentResultListener import com.razorpay.PaymentResultListener
import com.shabinder.common.database.activityContext import com.shabinder.common.database.activityContext
@ -58,6 +63,7 @@ import com.shabinder.common.models.TrackDetails
import com.shabinder.common.root.SpotiFlyerRoot import com.shabinder.common.root.SpotiFlyerRoot
import com.shabinder.common.root.callbacks.SpotiFlyerRootCallBacks import com.shabinder.common.root.callbacks.SpotiFlyerRootCallBacks
import com.shabinder.common.uikit.* import com.shabinder.common.uikit.*
import com.shabinder.common.uikit.utils.verticalGradientScrim
import com.shabinder.spotiflyer.utils.* import com.shabinder.spotiflyer.utils.*
import com.tonyodev.fetch2.Status import com.tonyodev.fetch2.Status
import kotlinx.coroutines.* import kotlinx.coroutines.*
@ -88,27 +94,32 @@ class MainActivity : ComponentActivity(), PaymentResultListener {
setContent { setContent {
SpotiFlyerTheme { SpotiFlyerTheme {
Surface(contentColor = colorOffWhite) { Surface(contentColor = colorOffWhite) {
ProvideWindowInsets {
var statusBarHeight by remember { mutableStateOf(27.dp) }
permissionGranted = remember { mutableStateOf(true) } permissionGranted = remember { mutableStateOf(true) }
val view = LocalView.current val view = LocalView.current
LaunchedEffect(view) { LaunchedEffect(view) {
permissionGranted.value = checkPermissions() permissionGranted.value = checkPermissions()
view.setOnApplyWindowInsetsListener { _, insets ->
statusBarHeight = insets.systemWindowInsetTop.dp
insets
} }
Box {
root = SpotiFlyerRootContent(
rememberRootComponent(::spotiFlyerRoot),
Modifier.statusBarsPadding().navigationBarsPadding()
)
Spacer(
Modifier
.statusBarsHeight()
.fillMaxWidth()
.background(MaterialTheme.colors.background.copy(alpha = 0.65f))
)
} }
root = SpotiFlyerRootContent(rememberRootComponent(::spotiFlyerRoot),statusBarHeight)
NetworkDialog() NetworkDialog()
PermissionDialog() PermissionDialog()
} }
} }
} }
}
initialise() initialise()
} }

View File

@ -33,4 +33,9 @@ allprojects {
maven(url = "https://dl.bintray.com/kotlin/kotlin-js-wrappers") maven(url = "https://dl.bintray.com/kotlin/kotlin-js-wrappers")
maven(url = "https://maven.pkg.jetbrains.space/public/p/compose/dev") maven(url = "https://maven.pkg.jetbrains.space/public/p/compose/dev")
} }
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
kotlinOptions {
useIR = true
}
}
} }

View File

@ -36,7 +36,7 @@ dependencies {
implementation("com.android.tools.build:gradle:4.0.2") implementation("com.android.tools.build:gradle:4.0.2")
implementation("com.google.gms:google-services:4.3.5") implementation("com.google.gms:google-services:4.3.5")
implementation("com.google.firebase:perf-plugin:1.3.5") implementation("com.google.firebase:perf-plugin:1.3.5")
implementation("com.google.firebase:firebase-crashlytics-gradle:2.5.1") implementation("com.google.firebase:firebase-crashlytics-gradle:2.5.2")
implementation("org.jlleitschuh.gradle:ktlint-gradle:${Versions.ktLint}") implementation("org.jlleitschuh.gradle:ktlint-gradle:${Versions.ktLint}")
implementation(JetBrains.Compose.gradlePlugin) implementation(JetBrains.Compose.gradlePlugin)
implementation(JetBrains.Kotlin.gradlePlugin) implementation(JetBrains.Kotlin.gradlePlugin)

View File

@ -17,13 +17,13 @@
@file:Suppress("MayBeConstant", "SpellCheckingInspection") @file:Suppress("MayBeConstant", "SpellCheckingInspection")
object Versions { object Versions {
// App's Version (To be bumped at each update)
const val versionName = "2.2.0" const val versionName = "2.2.0"
const val kotlinVersion = "1.4.31"
// Kotlin
const val kotlinVersion = "1.4.32"
const val coroutinesVersion = "1.4.2" const val coroutinesVersion = "1.4.2"
const val coilVersion = "0.4.1"
// Code Formatting // Code Formatting
const val ktLint = "10.0.0" const val ktLint = "10.0.0"
@ -34,9 +34,9 @@ object Versions {
const val kermit = "0.1.8" const val kermit = "0.1.8"
// Internet // Internet
const val ktor = "1.5.2" const val ktor = "1.5.3"
const val kotlinxSerialization = "1.1.0-RC" const val kotlinxSerialization = "1.1.0"
// Database // Database
const val sqlDelight = "1.4.4" const val sqlDelight = "1.4.4"
@ -86,19 +86,19 @@ object JetBrains {
object Compose { object Compose {
// __LATEST_COMPOSE_RELEASE_VERSION__ // __LATEST_COMPOSE_RELEASE_VERSION__
const val VERSION = "0.3.2" const val VERSION = "0.4.0-build182"
const val gradlePlugin = "org.jetbrains.compose:compose-gradle-plugin:$VERSION" const val gradlePlugin = "org.jetbrains.compose:compose-gradle-plugin:$VERSION"
} }
} }
object Decompose { object Decompose {
private const val VERSION = "0.1.9" private const val VERSION = "0.2.1"
const val decompose = "com.arkivanov.decompose:decompose:$VERSION" const val decompose = "com.arkivanov.decompose:decompose:$VERSION"
const val decomposeIosX64 = "com.arkivanov.decompose:decompose-iosx64:$VERSION" const val decomposeIosX64 = "com.arkivanov.decompose:decompose-iosx64:$VERSION"
const val decomposeIosArm64 = "com.arkivanov.decompose:decompose-iosarm64:$VERSION" const val decomposeIosArm64 = "com.arkivanov.decompose:decompose-iosarm64:$VERSION"
const val extensionsCompose = "com.arkivanov.decompose:extensions-compose-jetbrains:$VERSION" const val extensionsCompose = "com.arkivanov.decompose:extensions-compose-jetbrains:$VERSION"
} }
object MVIKotlin { object MVIKotlin {
private const val VERSION = "2.0.0" private const val VERSION = "2.0.1"
const val rx = "com.arkivanov.mvikotlin:rx:$VERSION" const val rx = "com.arkivanov.mvikotlin:rx:$VERSION"
const val mvikotlin = "com.arkivanov.mvikotlin:mvikotlin:$VERSION" const val mvikotlin = "com.arkivanov.mvikotlin:mvikotlin:$VERSION"
const val mvikotlinMain = "com.arkivanov.mvikotlin:mvikotlin-main:$VERSION" const val mvikotlinMain = "com.arkivanov.mvikotlin:mvikotlin-main:$VERSION"

View File

@ -22,15 +22,23 @@ plugins {
} }
kotlin { kotlin {
jvm("desktop") jvm("desktop").compilations.all {
android() kotlinOptions {
useIR = true
}
}
android().compilations.all {
kotlinOptions {
useIR = true
}
}
sourceSets { sourceSets {
named("commonMain") { named("commonMain") {
dependencies { dependencies {
implementation(compose.runtime) implementation(compose.runtime)
implementation(compose.foundation) implementation(compose.foundation)
implementation(compose.material) implementation(compose.material)
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.3") implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.3-native-mt")
} }
} }

View File

@ -21,10 +21,21 @@ plugins {
} }
kotlin { kotlin {
jvm("desktop") jvm("desktop").compilations.all {
android() kotlinOptions {
// ios() useIR = true
}
}
android().compilations.all {
kotlinOptions {
useIR = true
}
}
js() { js() {
/*
* TODO Enable JS IR Compiler
* waiting for Decompose & MVI Kotlin to support same
* */
browser() browser()
// nodejs() // nodejs()
binaries.executable() binaries.executable()

View File

@ -22,9 +22,21 @@ plugins {
} }
kotlin { kotlin {
jvm("desktop") jvm("desktop").compilations.all {
android() kotlinOptions {
useIR = true
}
}
android().compilations.all {
kotlinOptions {
useIR = true
}
}
js() { js() {
/*
* TODO Enable JS IR Compiler
* waiting for Decompose & MVI Kotlin to support same
* */
browser() browser()
// nodejs() // nodejs()
binaries.executable() binaries.executable()

View File

@ -14,6 +14,8 @@
* * along with this program. If not, see <https://www.gnu.org/licenses/>. * * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
@file:Suppress("EXPERIMENTAL_API_USAGE")
package com.shabinder.common.uikit package com.shabinder.common.uikit
import androidx.compose.animation.core.MutableTransitionState import androidx.compose.animation.core.MutableTransitionState
@ -37,6 +39,7 @@ import androidx.compose.foundation.layout.size
import androidx.compose.material.MaterialTheme import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text import androidx.compose.material.Text
import androidx.compose.material.TopAppBar import androidx.compose.material.TopAppBar
import androidx.compose.material.ripple.RippleAlpha
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
@ -48,6 +51,7 @@ import androidx.compose.ui.platform.LocalViewConfiguration
import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import com.arkivanov.decompose.extensions.compose.jetbrains.Children import com.arkivanov.decompose.extensions.compose.jetbrains.Children
import com.arkivanov.decompose.extensions.compose.jetbrains.animation.child.crossfadeScale
import com.shabinder.common.root.SpotiFlyerRoot import com.shabinder.common.root.SpotiFlyerRoot
import com.shabinder.common.root.SpotiFlyerRoot.Child import com.shabinder.common.root.SpotiFlyerRoot.Child
import com.shabinder.common.uikit.splash.Splash import com.shabinder.common.uikit.splash.Splash
@ -58,39 +62,39 @@ import com.shabinder.common.uikit.utils.verticalGradientScrim
private var isSplashShown = SplashState.Shown private var isSplashShown = SplashState.Shown
@Composable @Composable
fun SpotiFlyerRootContent(component: SpotiFlyerRoot, statusBarHeight: Dp = 0.dp): SpotiFlyerRoot { fun SpotiFlyerRootContent(component: SpotiFlyerRoot, modifier: Modifier = Modifier): SpotiFlyerRoot {
val transitionState = remember { MutableTransitionState(SplashState.Shown) } val transitionState = remember { MutableTransitionState(SplashState.Shown) }
val transition = updateTransition(transitionState) val transition = updateTransition(transitionState, label = "transition")
val splashAlpha by transition.animateFloat( val splashAlpha by transition.animateFloat(
transitionSpec = { tween(durationMillis = 100) } transitionSpec = { tween(durationMillis = 100) }, label = "Splash-Alpha"
) { ) {
if (it == SplashState.Shown && isSplashShown == SplashState.Shown) 1f else 0f if (it == SplashState.Shown && isSplashShown == SplashState.Shown) 1f else 0f
} }
val contentAlpha by transition.animateFloat( val contentAlpha by transition.animateFloat(
transitionSpec = { tween(durationMillis = 300) } transitionSpec = { tween(durationMillis = 300) }, label = "Content-Alpha"
) { ) {
if (it == SplashState.Shown && isSplashShown == SplashState.Shown) 0f else 1f if (it == SplashState.Shown && isSplashShown == SplashState.Shown) 0f else 1f
} }
val contentTopPadding by transition.animateDp( val contentTopPadding by transition.animateDp(
transitionSpec = { spring(stiffness = StiffnessLow) } transitionSpec = { spring(stiffness = StiffnessLow) }, label = "Content-Padding"
) { ) {
if (it == SplashState.Shown && isSplashShown == SplashState.Shown) 100.dp else 0.dp if (it == SplashState.Shown && isSplashShown == SplashState.Shown) 100.dp else 0.dp
} }
Box { Box {
Splash( Splash(
modifier = Modifier.alpha(splashAlpha), modifier = modifier.alpha(splashAlpha),
onTimeout = { onTimeout = {
transitionState.targetState = SplashState.Completed transitionState.targetState = SplashState.Completed
isSplashShown = SplashState.Completed isSplashShown = SplashState.Completed
} }
) )
MainScreen( MainScreen(
Modifier.alpha(contentAlpha), modifier,
contentAlpha,
contentTopPadding, contentTopPadding,
statusBarHeight,
component component
) )
} }
@ -98,20 +102,19 @@ fun SpotiFlyerRootContent(component: SpotiFlyerRoot, statusBarHeight: Dp = 0.dp)
} }
@Composable @Composable
fun MainScreen(modifier: Modifier = Modifier, topPadding: Dp = 0.dp, statusBarHeight: Dp = 0.dp, component: SpotiFlyerRoot) { fun MainScreen(modifier: Modifier = Modifier, alpha: Float,topPadding: Dp = 0.dp, component: SpotiFlyerRoot) {
val appBarColor = MaterialTheme.colors.surface.copy(alpha = 0.65f) val appBarColor = MaterialTheme.colors.surface.copy(alpha = 0.65f)
Column( Column(
modifier = modifier.fillMaxSize() modifier = Modifier.fillMaxSize()
.alpha(alpha)
.verticalGradientScrim( .verticalGradientScrim(
color = colorPrimaryDark.copy(alpha = 0.38f), color = colorPrimaryDark.copy(alpha = 0.38f),
startYPercentage = 0.29f, startYPercentage = 0.29f,
endYPercentage = 0f, endYPercentage = 0f,
) ).then(modifier)
) { ) {
Spacer(Modifier.background(appBarColor).height(statusBarHeight).fillMaxWidth())
LocalViewConfiguration.current
AppBar( AppBar(
backgroundColor = appBarColor, backgroundColor = appBarColor,
@ -120,8 +123,9 @@ fun MainScreen(modifier: Modifier = Modifier, topPadding: Dp = 0.dp, statusBarHe
Spacer(Modifier.padding(top = topPadding)) Spacer(Modifier.padding(top = topPadding))
Children( Children(
routerState = component.routerState, routerState = component.routerState,
) { child, _ -> animation = crossfadeScale()
when (child) { ) {
when (val child = it.instance) {
is Child.Main -> SpotiFlyerMainContent(component = child.component) is Child.Main -> SpotiFlyerMainContent(component = child.component)
is Child.List -> SpotiFlyerListContent(component = child.component) is Child.List -> SpotiFlyerListContent(component = child.component)
} }

View File

@ -43,7 +43,7 @@ internal class SpotiFlyerRootImpl(
router<Configuration, Child>( router<Configuration, Child>(
initialConfiguration = Configuration.Main, initialConfiguration = Configuration.Main,
handleBackButton = true, handleBackButton = true,
componentFactory = ::createChild childFactory = ::createChild
) )
override val routerState: Value<RouterState<*, Child>> = router.state override val routerState: Value<RouterState<*, Child>> = router.state