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

Add WatchOS support #648

Merged
merged 18 commits into from
Apr 19, 2024
Merged

Conversation

FabioCornelli
Copy link
Contributor

@FabioCornelli FabioCornelli commented Feb 28, 2024

Hi, we are using moko-resources in our KMP mobile app (iOS & Android) mostly for strings localization and is working great!
Recently, we were asked to try to extend part of our application on watchOS and we found out that moko-resources does not target watchOS (see #74 )

So with these PR I've tried to add watchOS targets to moko-resources project.

Most of the code of "resources" project was already written in "appleMain" source set, so it was already compatible also on watchOS.
The "resources-generator" plugin code was also already generating .strings file correctly for watchOS targets.

So in this PR I've basically done the following:

  • reworked "multiplatform-library-convention.gradle.kts" and "apple-main-convention.gradle.kts" in order to define watchOS source sets
  • added watchOS targets in "resources" and "resources-test" projects
  • implemented the expected classes and methods for watchOS targets
  • added a watchOS target to the "kotlin-ios-app" sample project and test my modifications

I've run the sample on watchOS simulator and it seems to work correctly.

There a couple of things that i think can be improved:

  1. I think the method internal expect fun Color.toUIColor(): UIColor should probably be moved in "moko-graphics" library. Shall I open a PR on moko-graphics ? if so, it's probably better to have a version of "moko-graphics" that support watchOS before moving on this PR.
  2. I'm not sure that having "kotlin-ios-app" with two target (iOS app and watchOS app) is a good approach or not, since it was giving me some issues in building the project correctly (which I solved by disabling gradle cache, see the last commit on this PR).
    If somebody has a better idea on how watchOS target can be tested, I'm open for suggestions and feedback.

Finally, with this PR I'm targeting #575 branch instead of develop because I've read in #624 that in #575 the plugin was rewritten.

Please let me know if that is correct or i should point to a different branch.

we need also to define watchos64 and watchos32 intermediate source set
because some apple api are different on 64 and 32 bit architecture

(watchosArm64 target is actually arm64_32, which is a variant of arm64 with 32-bit pointer sizes, used on Apple Watch Series 4 and later.)
expected classes:

  - FontResource
  - ImageResource

expected methods:

  - ColorDesc.getUIColor(): UIColor
  - ColorResource.getUIColor()
  - ResourceContainer<ImageResource>.getImageByFileName(fileName: String): ImageResource?


Some classes / methods needed some changes due to some api not being available on watchos.

e.g. ImageResource could not get UIImage from specific bundle
e.g. FontResource needed different implementation for watchos64 and watchos32 due to different pointer size.
added also a watchos app target in kotlin-ios-app sample project
sample app gives the following error if configuration cache is enabled:

error: Build input file cannot be found: '<USER_PATH>/Build/Products/Debug-iphonesimulator/TestKotlinApp.app/TestKotlinApp'. Did you forget to declare this file as an output of a script phase or custom build rule which produces it?
@Alex009 Alex009 added this to the 0.24.0 milestone Apr 11, 2024
@ExNDY
Copy link
Contributor

ExNDY commented Apr 17, 2024

@FabioCornelli Hi, can u check latest commits on watchOs? I'm merge latest version of branch, change FontResource with latest version of Apple variant FontResource. Thank you

@Alex009 Alex009 deleted the branch icerockdev:develop April 18, 2024 14:00
@Alex009 Alex009 closed this Apr 18, 2024
@Alex009 Alex009 reopened this Apr 18, 2024
@Alex009 Alex009 changed the base branch from #535-kotlin-1.9.0-support to develop April 18, 2024 14:06
Copy link
Member

@Alex009 Alex009 left a comment

Choose a reason for hiding this comment

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

conflict should be resolved

ExNDY added 3 commits April 19, 2024 08:19
# Conflicts:
#	resources/src/appleMain/kotlin/dev/icerock/moko/resources/FontResource.kt
# Conflicts:
#	resources/src/appleMain/kotlin/dev/icerock/moko/resources/NSErrorException.kt
@Alex009 Alex009 linked an issue Apr 19, 2024 that may be closed by this pull request
11 tasks
@Alex009 Alex009 merged commit 7dcf26b into icerockdev:develop Apr 19, 2024
17 of 28 checks passed
@Alex009 Alex009 mentioned this pull request Jun 9, 2024
@muralex-e muralex-e mentioned this pull request Jul 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for other platforms
3 participants