Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[12] Integrate Moko Resources to share project resources between platforms #44

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
[submodule "android"]
path = android
url = [email protected]:nimblehq/android-templates.git
branch = feature/replace-hilt-with-koin
branch = feature/moko-resources
9 changes: 9 additions & 0 deletions buildSrc/src/main/java/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ object Dependencies {
const val COMMON_KTX = "com.github.nimblehq:android-common-ktx:${Versions.COMMON_KTX}"
}

object Moko {
const val RESOURCES_GENERATOR = "dev.icerock.moko:resources-generator:${Versions.MOKO_RESOURCES}"
const val RESOURCES = "dev.icerock.moko:resources:${Versions.MOKO_RESOURCES}"
const val RESOURCES_COMPOSE = "dev.icerock.moko:resources-compose:${Versions.MOKO_RESOURCES}"
const val GRAPHICS = "dev.icerock.moko:graphics:${Versions.MOKO_GRAPHICS}"
}

object Test {
const val COMPOSE_UI_TEST_JUNIT = "androidx.compose.ui:ui-test-junit4"
const val COROUTINES = "org.jetbrains.kotlinx:kotlinx-coroutines-test:${Versions.KOTLIN_COROUTINES}"
Expand All @@ -66,6 +73,8 @@ object Dependencies {
const val MOCKK = "io.mockk:mockk:${Versions.MOCKK}"
const val MOCKK_ANDROID = "io.mockk:mockk-android:${Versions.MOCKK}"

const val MOKO_RESOURCES_TEST = "dev.icerock.moko:resources-test:${Versions.MOKO_RESOURCES}"

const val ROBOLECTRIC = "org.robolectric:robolectric:${Versions.ROBOLECTRIC}"

const val TURBINE = "app.cash.turbine:turbine:${Versions.TURBINE}"
Expand Down
2 changes: 2 additions & 0 deletions buildSrc/src/main/java/Plugins.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ object Plugins {
const val KOVER = "org.jetbrains.kotlinx.kover"
const val KSP = "com.google.devtools.ksp"

const val MOKO = "dev.icerock.mobile.multiplatform-resources"

const val MULTIPLATFORM = "multiplatform"
}
3 changes: 3 additions & 0 deletions buildSrc/src/main/java/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ object Versions {
const val MOCKATIVE = "1.3.0"
const val MOCKK = "1.13.3"

const val MOKO_RESOURCES = "0.23.0"
const val MOKO_GRAPHICS = "0.9.0"

const val NAPIER = "2.6.1"

const val ROBOLECTRIC = "4.9.1"
Expand Down
2 changes: 1 addition & 1 deletion ios
Submodule ios updated 70 files
+0 −0 .github/project_workflows/automatic_pull_request_review.yml
+5 −0 .github/project_workflows/deploy_app_store.yml
+5 −0 .github/project_workflows/deploy_production_firebase.yml
+5 −0 .github/project_workflows/deploy_staging_firebase.yml
+0 −0 .github/project_workflows/draft_a_new_release.yml
+19 −0 .github/project_workflows/publish_docs_to_wiki.yml
+1 −2 .github/wiki/Deliverable-Configurations.md
+17 −1 .github/wiki/Getting-Started.md
+11 −0 .github/wiki/Selecting-User-Interface.md
+1 −0 .github/wiki/_Sidebar.md
+27 −0 .github/workflows/test_swiftui_install_script.yml
+3 −5 .github/workflows/test_uikit_install_script.yml
+7 −2 .github/workflows/test_upload_build_to_firebase.yml
+7 −2 .github/workflows/test_upload_build_to_test_flight.yml
+1 −0 .gitignore
+1 −0 .swiftlint.yml
+0 −2 Dangerfile
+2 −0 Gemfile
+2 −2 README.md
+14 −0 Scripts/Swift/iOSTemplateMaker/Package.resolved
+28 −0 Scripts/Swift/iOSTemplateMaker/Package.swift
+108 −0 Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/Extensions/FileManager+Utils.swift
+18 −0 Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/Extensions/Optional+Utils.swift
+11 −0 Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/Extensions/String+Utils.swift
+15 −0 Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/Helpers/EnvironmentValue.swift
+20 −0 Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/Helpers/SafeShell.swift
+23 −0 Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/Models/EnvironmentKey.swift
+57 −0 Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/SetUpCICDService.swift
+21 −0 Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/SetUpDeliveryConstants.swift
+49 −0 Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/SetUpInterface.swift
+23 −0 Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/SetUpTestFirebase.swift
+23 −0 Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/SetUpTestTestFlight.swift
+193 −0 Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/SetUpiOSProject.swift
+78 −0 Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/iOSTemplateMaker.swift
+0 −0 Scripts/Swift/iOSTemplateMaker/Tests/iOSTemplateMakerTests/.gitkeep
+0 −3 Tuist/Interfaces/SwiftUI/Project/.sourcery.yml
+61 −0 Tuist/Interfaces/SwiftUI/Project/Podfile
+10 −0 Tuist/Interfaces/SwiftUI/Sources/Application/App.swift
+0 −0 Tuist/Interfaces/SwiftUI/Sources/Presentation/Coordinators/.gitkeep
+0 −0 Tuist/Interfaces/SwiftUI/Sources/Presentation/Models/.gitkeep
+13 −0 Tuist/Interfaces/SwiftUI/Sources/Presentation/Modules/HomeView.swift
+0 −0 Tuist/Interfaces/SwiftUI/Sources/Presentation/Styles/.gitkeep
+0 −0 Tuist/Interfaces/SwiftUI/Sources/Presentation/ViewIds/.gitkeep
+0 −0 Tuist/Interfaces/SwiftUI/Sources/Presentation/ViewModifiers/.gitkeep
+0 −0 Tuist/Interfaces/SwiftUI/Sources/Presentation/Views/.gitkeep
+9 −0 Tuist/Interfaces/UIKit/Project/.sourcery.yml
+7 −10 Tuist/Interfaces/UIKit/Project/Podfile
+0 −0 Tuist/Interfaces/UIKit/Sources/Application/AppDelegate.swift
+1 −1 Tuist/Interfaces/UIKit/Sources/Presentation/Modules/HomeViewController.swift
+0 −0 Tuist/Interfaces/UIKit/Sources/Presentation/Navigator/Navigator+Scene.swift
+0 −0 Tuist/Interfaces/UIKit/Sources/Presentation/Navigator/Navigator+Transition.swift
+0 −0 Tuist/Interfaces/UIKit/Sources/Presentation/Navigator/Navigator.swift
+0 −0 Tuist/Interfaces/UIKit/Sources/Presentation/Views/.gitkeep
+0 −26 deliverable_setup.sh
+1 −1 fastlane/Constants/Constant.swift
+5 −0 fastlane/Fastfile.swift
+8 −0 fastlane/Helpers/Keychain.swift
+0 −215 make.sh
+0 −12 set_up_test_firebase.sh
+0 −12 set_up_test_testflight.sh
+9 −20 {PROJECT_NAME}/Sources/Data/NetworkAPI/Core/NetworkAPIProtocol.swift
+5 −4 {PROJECT_NAME}/Sources/Data/NetworkAPI/NetworkAPI.swift
+3 −3 {PROJECT_NAME}KIFUITests/Sources/Specs/Application/ApplicationSpec.swift
+5 −5 {PROJECT_NAME}KIFUITests/Sources/Utilities/KIF+Swift.swift
+10 −0 {PROJECT_NAME}KIFUITests/Sources/Utilities/KIFSpec.swift
+14 −0 {PROJECT_NAME}Tests/Sources/Dummy/Data/DummyNetworkModel.swift
+29 −0 {PROJECT_NAME}Tests/Sources/Dummy/Data/DummyRequestConfiguration.swift
+64 −0 {PROJECT_NAME}Tests/Sources/Specs/Data/NetworkAPI/NetworkAPISpec.swift
+1 −1 {PROJECT_NAME}Tests/Sources/Specs/Supports/Extensions/Foundation/OptionalUnwrapSpec.swift
+32 −0 {PROJECT_NAME}Tests/Sources/Utilities/NetworkStubber.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package co.nimblehq.kmm.template

import android.app.Application
import co.nimblehq.common.extensions.BuildConfig
import co.nimblehq.kmm.template.di.initKoin
import co.nimblehq.kmm.template.di.modules.appModule
import co.nimblehq.kmm.template.di.modules.viewModelModule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import co.nimblehq.kmm.template.R
import co.nimblehq.kmm.template.Strings
import co.nimblehq.kmm.template.extensions.collectAsEffect
import co.nimblehq.kmm.template.getPlatform
import co.nimblehq.kmm.template.sharedres.SharedRes
import co.nimblehq.kmm.template.ui.AppDestination
import co.nimblehq.kmm.template.ui.models.UiModel
import co.nimblehq.kmm.template.ui.showToast
Expand All @@ -32,15 +35,18 @@ fun HomeScreen(
val uiModels: List<UiModel> by viewModel.uiModels.collectAsStateWithLifecycle()

HomeScreenContent(
title = stringResource(id = R.string.app_name),
title = Strings(LocalContext.current).get(
id = SharedRes.strings.greeting,
args = listOf(getPlatform().name)
),
uiModels = uiModels
)
}

@Composable
private fun HomeScreenContent(
title: String,
uiModels: List<UiModel>
uiModels: List<UiModel>,
) {
Column(
modifier = Modifier.fillMaxSize(),
Expand Down
6 changes: 6 additions & 0 deletions sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ plugins {
kotlin(Plugins.KOTLIN_SERIALIZATION) version Versions.KOTLIN
}

buildscript {
dependencies {
classpath(Dependencies.Moko.RESOURCES_GENERATOR)
}
}

detekt {
toolVersion = Versions.DETEKT
config.setFrom("detekt.yml")
Expand Down
9 changes: 9 additions & 0 deletions sample/buildSrc/src/main/java/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ object Dependencies {
const val COMMON_KTX = "com.github.nimblehq:android-common-ktx:${Versions.COMMON_KTX}"
}

object Moko {
const val RESOURCES_GENERATOR = "dev.icerock.moko:resources-generator:${Versions.MOKO_RESOURCES}"
const val RESOURCES = "dev.icerock.moko:resources:${Versions.MOKO_RESOURCES}"
const val RESOURCES_COMPOSE = "dev.icerock.moko:resources-compose:${Versions.MOKO_RESOURCES}"
const val GRAPHICS = "dev.icerock.moko:graphics:${Versions.MOKO_GRAPHICS}"
}

object Test {
const val COMPOSE_UI_TEST_JUNIT = "androidx.compose.ui:ui-test-junit4"
const val COROUTINES = "org.jetbrains.kotlinx:kotlinx-coroutines-test:${Versions.KOTLIN_COROUTINES}"
Expand All @@ -66,6 +73,8 @@ object Dependencies {
const val MOCKK = "io.mockk:mockk:${Versions.MOCKK}"
const val MOCKK_ANDROID = "io.mockk:mockk-android:${Versions.MOCKK}"

const val MOKO_RESOURCES_TEST = "dev.icerock.moko:resources-test:${Versions.MOKO_RESOURCES}"

const val ROBOLECTRIC = "org.robolectric:robolectric:${Versions.ROBOLECTRIC}"

const val TURBINE = "app.cash.turbine:turbine:${Versions.TURBINE}"
Expand Down
2 changes: 2 additions & 0 deletions sample/buildSrc/src/main/java/Plugins.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ object Plugins {
const val KOVER = "org.jetbrains.kotlinx.kover"
const val KSP = "com.google.devtools.ksp"

const val MOKO = "dev.icerock.mobile.multiplatform-resources"

const val MULTIPLATFORM = "multiplatform"
}
3 changes: 3 additions & 0 deletions sample/buildSrc/src/main/java/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ object Versions {
const val MOCKATIVE = "1.3.0"
const val MOCKK = "1.13.3"

const val MOKO_RESOURCES = "0.23.0"
const val MOKO_GRAPHICS = "0.9.0"

const val NAPIER = "2.6.1"

const val ROBOLECTRIC = "4.9.1"
Expand Down
13 changes: 13 additions & 0 deletions sample/shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ plugins {
id(Plugins.KOVER)
id(Plugins.KSP)
id(Plugins.BUILD_KONFIG)
id(Plugins.MOKO)
}

@OptIn(org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi::class)
Expand All @@ -36,6 +37,8 @@ kotlin {
podfile = project.file("../ios/Podfile")
framework {
baseName = "shared"
export(Dependencies.Moko.RESOURCES)
export(Dependencies.Moko.GRAPHICS)
}

xcodeConfigurationToNativeBuildType["Debug Staging"] = NativeBuildType.DEBUG
Expand All @@ -60,6 +63,11 @@ kotlin {
}

implementation(Dependencies.Log.NAPIER)

with(Dependencies.Moko) {
api(RESOURCES)
api(RESOURCES_COMPOSE) FIXME: Cannot build the shared module with this dependency
}
}
}
val commonTest by getting {
Expand Down Expand Up @@ -145,3 +153,8 @@ buildkonfig {
)
}
}

multiplatformResources {
multiplatformResourcesPackage = "co.nimblehq.kmm.template.sharedres"
multiplatformResourcesClassName = "SharedRes"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package co.nimblehq.kmm.template

import android.content.Context
import dev.icerock.moko.resources.StringResource
import dev.icerock.moko.resources.desc.Resource
import dev.icerock.moko.resources.desc.StringDesc
import dev.icerock.moko.resources.format

actual class Strings(private val context: Context) {
actual fun get(
id: StringResource,
args: List<Any>,
): String {
return if (args.isEmpty()) {
StringDesc.Resource(id).toString(context = context)
} else {
id.format(*args.toTypedArray()).toString(context)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package co.nimblehq.kmm.template

import dev.icerock.moko.resources.StringResource

expect class Strings {
fun get(id: StringResource, args: List<Any> = emptyList()): String
}
3 changes: 3 additions & 0 deletions sample/shared/src/commonMain/resources/MR/base/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>
<string name="greeting">Hello, %s!</string>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package co.nimblehq.kmm.template

import dev.icerock.moko.resources.StringResource
import dev.icerock.moko.resources.desc.Resource
import dev.icerock.moko.resources.desc.StringDesc
import dev.icerock.moko.resources.format

actual class Strings {
actual fun get(
id: StringResource,
args: List<Any>,
): String {
return if (args.isEmpty()) {
StringDesc.Resource(id).localized()
} else {
id.format(*args.toTypedArray()).localized()
}
}
}
13 changes: 13 additions & 0 deletions shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ plugins {
id(Plugins.KOVER)
id(Plugins.KSP)
id(Plugins.BUILD_KONFIG)
id(Plugins.MOKO)
}

@OptIn(org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi::class)
Expand All @@ -36,6 +37,8 @@ kotlin {
podfile = project.file("../ios/Podfile")
framework {
baseName = "shared"
export(Dependencies.Moko.RESOURCES)
export(Dependencies.Moko.GRAPHICS)
}

xcodeConfigurationToNativeBuildType["Debug Staging"] = NativeBuildType.DEBUG
Expand All @@ -60,6 +63,11 @@ kotlin {
}

implementation(Dependencies.Log.NAPIER)

with(Dependencies.Moko) {
api(RESOURCES)
api(RESOURCES_COMPOSE)
}
}
}
val commonTest by getting {
Expand Down Expand Up @@ -145,3 +153,8 @@ buildkonfig {
)
}
}

multiplatformResources {
multiplatformResourcesPackage = "co.nimblehq.kmm.template.sharedres"
multiplatformResourcesClassName = "SharedRes"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package co.nimblehq.kmm.template

import android.content.Context
import dev.icerock.moko.resources.StringResource
import dev.icerock.moko.resources.desc.Resource
import dev.icerock.moko.resources.desc.StringDesc
import dev.icerock.moko.resources.format

actual class Strings(private val context: Context) {
actual fun get(
id: StringResource,
args: List<Any>,
): String {
return if (args.isEmpty()) {
StringDesc.Resource(id).toString(context = context)
} else {
id.format(*args.toTypedArray()).toString(context)
Copy link

@github-actions github-actions bot Sep 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ In most cases using a spread operator causes a full copy of the array to be created before calling a method. This may result in a performance penalty.

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package co.nimblehq.kmm.template

import dev.icerock.moko.resources.StringResource

expect class Strings {
fun get(id: StringResource, args: List<Any> = emptyList()): String
}
3 changes: 3 additions & 0 deletions shared/src/commonMain/resources/MR/base/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>
<string name="greeting">Hello, %s!</string>
</resources>
19 changes: 19 additions & 0 deletions shared/src/iosMain/kotlin/co/nimblehq/kmm/template/Strings.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package co.nimblehq.kmm.template

import dev.icerock.moko.resources.StringResource
import dev.icerock.moko.resources.desc.Resource
import dev.icerock.moko.resources.desc.StringDesc
import dev.icerock.moko.resources.format

actual class Strings {
actual fun get(
id: StringResource,
args: List<Any>,
): String {
return if (args.isEmpty()) {
StringDesc.Resource(id).localized()
} else {
id.format(*args.toTypedArray()).localized()
Copy link

@github-actions github-actions bot Sep 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ In most cases using a spread operator causes a full copy of the array to be created before calling a method. This may result in a performance penalty.

}
}
}
Loading