Compose Cupertino

repository·master·Indexed 23 days ago

https://github.com/alexzhirkevich/compose-cupertino

A Kotlin Multiplatform library providing iOS-style UI components and adaptive themes for Compose Multiplatform. It includes modules for Cupertino widgets, UIKit native wrappers, adaptive themes that switch between Material 3 and Cupertino styles, SF Symbols as ImageVectors, and Decompose integration for iOS-like navigation and swipe-back animations.

Tokens
4.8K
Snippets
5
Records
30
Agent score
75%

What's inside Compose Cupertino

  1. Overview of Compose Cupertino modules

    master

    Compose Cupertino is a Kotlin Multiplatform library designed for Compose Multiplatform to create native-looking iOS applications. It is divided into several specialized modules:

    • cupertino: A Compose Multiplatform implementation of iOS-style themes and widgets based on compose.foundation. It is inspired by compose.material3 and SwiftUI APIs.
    • cupertino-native: Provides UIKit native wrappers for Cupertino widgets. This allows you to use actual UIKit widgets on iOS while using their Cupertino equivalents on other platforms.
    • cupertino-adaptive: Provides adaptive themes and wrappers for both Cupertino and Material3 widgets. This allows you to write shared code that automatically uses the correct widget style (Material You or iOS) and styling (colors/fonts) based on the platform.
    • cupertino-icons-extended: Contains over 800 monochrome Apple SF Symbols as Compose ImageVectors. Note: These are copyrighted; check the license agreement. If you only need icons for iOS, you can use bundled icons via converters in cupertino-native instead.
    • cupertino-decompose: Integrates with the Decompose library to provide iOS-like swipe-back animations for 'predictive back' navigation and includes a NativeChildren wrapper over UINavigationController for native page transitions and gestures.
  2. Available iOS-style components

    master

    The library provides a variety of iOS-style widgets that support both light and dark modes. The following components are available:

    • Buttons: CupertinoButton, CupertinoIconButton
    • Date Picker: CupertinoDatePicker
    • Dialogs: CupertinoDialog, CupertinoDialogNative
    • Divider: CupertinoDivider
    • Navigation: CupertinoNavigationBar (use CupertinoNavigationBarItem for items)
    • Progress Indicator: CupertinoActivityIndicator
    • Layout: CupertinoScaffold (recommended for use with top bars and navigation bars)
    • Slider: CupertinoSlider
    • Switch: CupertinoSwitch
    • Top App Bar: CupertinoTopAppBar
  3. Add Compose Cupertino artifacts to your project

    master

    You can include the various Compose Cupertino modules in your Kotlin Multiplatform project via Maven Central. Replace <version> with the desired version (e.g., 0.1.0-alpha04).

    ModuleDependency
    cupertinoio.github.alexzhirkevich:cupertino:<version>
    cupertino-nativeio.github.alexzhirkevich:cupertino-native:<version>
    cupertino-adaptiveio.github.alexzhirkevich:cupertino-adaptive:<version>
    cupertino-decomposeio.github.alexzhirkevich:cupertino-decompose:<version>
    cupertino-icons-extendedio.github.alexzhirkevich:cupertino-icons-extended:<version>
  4. Apply the CupertinoTheme to your app

    master

    To use iOS-style components from the library, you must wrap your application's content in a CupertinoTheme composable. This provides the necessary styling and theme context for all Cupertino widgets.

    @Composable
    fun AppTheme(
        content: @Composable () -> Unit
    ) {
        CupertinoTheme(content = content)
    }
  5. Configure AdaptiveTheme for Material and Cupertino support

    master

    To use adaptive components that switch between Material and Cupertino designs based on a target platform, you must wrap your application's theme in AdaptiveTheme. This allows you to provide specific theme configurations for both material and cupertino branches, which are then applied based on the target parameter.

    @Composable
    fun AppTheme(
        theme: Theme,
        content: @Composable () -> Unit
    ) {
        AdaptiveTheme(
            material = {
                // Tweak this for your Material design
                MaterialTheme(content = it)
            },
            cupertino = {
                // Tweak this for your iOS design
                CupertinoTheme(content = it)
            },
            target = theme,
            content = content
        )
    }
  6. Customize AdaptiveIconButton appearance via AdaptationScope

    master

    Both AdaptiveIconButton and AdaptiveFilledIconButton accept an adaptation lambda. This lambda provides an AdaptationScope where you can access and modify the adaptation objects for both platforms.

    Inside the scope, you can access:

    • CupertinoIconButtonAdaptation: To modify colors using CupertinoButtonColors.
    • MaterialIconButtonAdaptation: To modify colors using IconButtonColors (Material 3).
  7. Customize AdaptiveCircularProgressIndicator via Adaptation Scopes

    master

    When using AdaptiveCircularProgressIndicator, you can use the adaptationScope to configure platform-specific properties. The scope provides two adaptation objects:

    MaterialCircularProgressIndicatorAdaptation

    Used to configure the Material CircularProgressIndicator:

    • color: The color of the indicator.
    • trackColor: The color of the track.
    • strokeWidth: The thickness of the stroke.
    • strokeCap: The cap style of the stroke.

    CupertinoCircularProgressIndicatorAdaptation

    Used to configure the CupertinoActivityIndicator:

    • color: The color of the indicator.
    • progress: The progress value (Float).
    • size: The size of the indicator.
    • count: The number of paths/indicators.
    • innerRadius: The inner radius of the indicator.
    • strokeWidth: The thickness of the stroke.
    • animationSpec: The InfiniteRepeatableSpec for the animation.
    • minAlpha: The minimum alpha value during animation.
  8. Create custom adaptive components with AdaptiveWidget

    master

    If you want to build your own components that automatically switch appearance based on the current platform, use the AdaptiveWidget composable. You provide two lambda blocks: material for the Android/Material design and cupertino for the iOS/Cupertino design.

    @Composable
    fun MyWidget() {
        AdaptiveWidget(
            material = { Text("Your Material design here") },
            cupertino = { Text("Your Cupertino design here") }
        )
    }
  9. Reference of available Adaptive components

    master

    The following components are available in the library and will automatically adapt their design based on the AdaptiveTheme target. All components support both light and dark modes.

    • Buttons: AdaptiveButton, AdaptiveIconButton
    • Date picker: AdaptiveDatePicker
    • Dialog: AdaptiveDialog, AdaptiveDialogNative
    • Divider: AdaptiveDivider
    • Navigation bar: AdaptiveCupertinoNavigationBar (use AdaptiveNavigationBarItem for items)
    • Progress indicator: AdaptiveCircularProgressIndicator
    • Scaffold: AdaptiveScaffold (recommended for use with top bars and navigation bars)
    • Slider: AdaptiveSlider
    • Switch: AdaptiveSwitch
    • Top app bar: AdaptiveTopAppBar
  10. Use AdaptiveFilledIconButton for filled icon buttons

    master

    The AdaptiveFilledIconButton component provides an adaptive version of the Material FilledIconButton. It switches between a Material FilledIconButton and a CupertinoIconButton (configured with filled colors) depending on the platform.

    This is the preferred component when you want a high-emphasis icon button that uses a background color.

  11. Use AdaptiveCheckbox for platform-aware checkboxes

    master

    The AdaptiveCheckbox composable provides a checkbox that automatically switches between Material 3 (Checkbox) and Cupertino (CupertinoCheckBox) styles based on the current platform or adaptation scope.

    It supports standard checkbox parameters such as checked, onCheckedChange, modifier, enabled, and interactionSource. You can further customize the appearance for both platforms using the adaptation lambda, which provides access to CupertinoCheckBoxAdaptation and MaterialCheckBoxAdaptation scopes.