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

[BIG-PR] Refactor Android-Specific Code to Kotlin Multiplatform Support #70

Merged
merged 11 commits into from
Nov 13, 2024

Conversation

AmniX
Copy link
Contributor

@AmniX AmniX commented Nov 11, 2024

Overview:

In this PR, I have refactored the project to move both the UI components and network-related code from the Android-specific implementation to the shared module. Previously, the shared module was only used for non-UI code, such as network API calls and business logic, while the UI was Android-specific. With this change, both the UI and network code are now part of the shared module, allowing us to leverage Kotlin Multiplatform and Compose for both Android and iOS. This shift will enable us to reuse the UI components across both platforms and improve the maintainability and consistency of the codebase.

Changes Made:

  1. Moved UI Code to Shared Module:

    • Migrated all Android-specific Compose UI code into the shared module. The shared module now includes UI components that can be used for both Android and iOS.
    • Earlier the UI was built on Android Compose but now It will use Jetbrains fork of Compose which is almost same for android except a few refactors which were platform dependent i.e. webview.
    • Separated platform-specific UI logic (such as navigation or gestures) into platform-specific implementations using expect/actual where needed.
  2. Network Code in Shared Module:

    • The network-related code, which was previously in the shared module, remains in place and is now complemented with the UI components. The shared module now contains both the network logic and the UI components that interact with this data.
    • Ensured that the API calls, data models, and network utilities work seamlessly across both Android and iOS.
  3. Platform-Specific Implementations:

    • Used expect/actual mechanisms to manage platform-specific differences, such as different handling of navigation or platform-specific APIs. This ensures that the shared module can accommodate platform-specific requirements without duplicating logic.
  4. Compose Multiplatform Support:

    • Refactored Compose UI code to ensure compatibility with Compose for iOS. The shared module now includes the UI components necessary for rendering on both Android and iOS using the same codebase.
    • Introduced platform-specific UI adjustments (if any) through conditional code, ensuring that the UI behaves as expected on both platforms.
  5. Dependencies Updated:

    • Updated dependencies to support Kotlin Multiplatform and Compose for Multi Mobile Platform, ensuring that both Android and iOS platforms can use the shared module effectively.
    • Added basic configurations for iOS, including XCFramework integration for shared code access.
  6. iOS Support:

    • Set up the necessary infrastructure for using the shared module in the iOS target, including configuring the appropriate Kotlin Multiplatform settings and ensuring that the UI and network components are accessible from the iOS project.

Key Benefits:

  • Full Code Reusability: By consolidating both UI and network code in the shared module, we now have a unified codebase for both Android and iOS, minimizing code duplication and ensuring that updates to business logic or UI are reflected on both platforms.
  • Improved Maintainability: The shared module is now the central hub for both UI and non-UI code, streamlining the maintenance process. With fewer platform-specific code branches, managing and extending the codebase is easier.
  • Scalability: With this refactor, it's easier to expand the app to support additional platforms (e.g., web) by simply adding new targets to the shared module.

Next Steps:

  • Bring a wrapped framework for iOS where ios framework will reuse the KMM sharedLibrary and the the ios framework will be reused in a sample app
  • Continue to optimize the UI for iOS, ensuring that the experience matches Android as closely as possible where needed.
  • Refactor any remaining platform-specific code that can be moved to the shared module.

Notes:

  • Ensure that platform-specific UI behaviors (such as navigation, gestures, and platform-specific themes) are implemented correctly on iOS.
  • Perform thorough testing of the UI on both platforms to ensure consistent look and feel.
  • Double-check the API layer to ensure that no platform-specific dependencies or issues exist with network handling.

@AmniX AmniX self-assigned this Nov 11, 2024
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit

ktlint

🚫 [ktlint] standard:function-start-of-body-spacing reported by reviewdog 🐶
Expected a single white space before start of function body

override fun viewWillDisappear(animated: Boolean){


🚫 [ktlint] standard:function-signature reported by reviewdog 🐶
Expected a single space before body block

override fun viewWillDisappear(animated: Boolean){


🚫 [ktlint] standard:no-blank-line-before-rbrace reported by reviewdog 🐶
Unexpected blank line(s) before "}"


🚫 [ktlint] standard:no-consecutive-blank-lines reported by reviewdog 🐶
Needless blank line(s)

@AmniX AmniX changed the title Refactor Android-Specific Code to Kotlin Multiplatform Support [BIG-PR] Refactor Android-Specific Code to Kotlin Multiplatform Support Nov 11, 2024
@AmniX AmniX merged commit eab520e into main Nov 13, 2024
2 checks passed
@AmniX AmniX deleted the amnix/move_sdk_ui_to_shared_module branch November 13, 2024 01:01
github-actions bot pushed a commit that referenced this pull request Nov 13, 2024
…ltiplatform Support (#70)

* Moved the SDK UI to the shared module

* ktlint fixup

* Use default Res Package directory

* Got rid of resources as iOS have issues with them.
Used code based resources as of now.

* Added Japanese i18n

* Dynamic height fraction

* ktlint fixup

* added more strings

* improved docs

* enum naming changes

* ktlint fixup
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.

1 participant