开源项目 multiplatform-compose 使用教程

开源项目 multiplatform-compose 使用教程

multiplatform-composeA demo to show usage of Jetbrains Compose in Android and iOS.项目地址:https://gitcode.com/gh_mirrors/mu/multiplatform-compose

1. 项目的目录结构及介绍

multiplatform-compose 项目的目录结构如下:

multiplatform-compose/
├── build.gradle.kts
├── settings.gradle.kts
├── README.md
├── common/
│   ├── src/
│   │   ├── commonMain/
│   │   │   ├── kotlin/
│   │   │   │   └── com/
│   │   │   │       └── example/
│   │   │   │           └── common/
│   │   │   │               └── Main.kt
│   │   │   └── resources/
│   │   └── commonTest/
│   │       ├── kotlin/
│   │       └── resources/
├── android/
│   ├── src/
│   │   ├── main/
│   │   │   ├── kotlin/
│   │   │   │   └── com/
│   │   │   │       └── example/
│   │   │   │           └── android/
│   │   │   │               └── MainActivity.kt
│   │   │   └── res/
│   │   └── test/
│   │       ├── kotlin/
│   │       └── resources/
├── ios/
│   ├── src/
│   │   ├── main/
│   │   │   ├── kotlin/
│   │   │   │   └── com/
│   │   │   │       └── example/
│   │   │   │           └── ios/
│   │   │   │               └── Main.kt
│   │   │   └── resources/
│   │   └── test/
│   │       ├── kotlin/
│   │       └── resources/
├── desktop/
│   ├── src/
│   │   ├── main/
│   │   │   ├── kotlin/
│   │   │   │   └── com/
│   │   │   │       └── example/
│   │   │   │           └── desktop/
│   │   │   │               └── Main.kt
│   │   │   └── resources/
│   │   └── test/
│   │       ├── kotlin/
│   │       └── resources/

目录结构介绍

  • build.gradle.ktssettings.gradle.kts:Gradle 构建脚本。
  • README.md:项目说明文档。
  • common/:包含跨平台的通用代码。
    • commonMain/:通用主代码。
    • commonTest/:通用测试代码。
  • android/:Android 平台相关代码。
    • main/:主代码。
    • test/:测试代码。
  • ios/:iOS 平台相关代码。
    • main/:主代码。
    • test/:测试代码。
  • desktop/:桌面平台相关代码。
    • main/:主代码。
    • test/:测试代码。

2. 项目的启动文件介绍

Android 平台

Android 平台的启动文件是 android/src/main/kotlin/com/example/android/MainActivity.kt。这个文件定义了 Android 应用的主活动(Activity)。

package com.example.android

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import com.example.common.MainView

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            MainView()
        }
    }
}

iOS 平台

iOS 平台的启动文件是 ios/src/main/kotlin/com/example/ios/Main.kt。这个文件定义了 iOS 应用的入口点。

package com.example.ios

import com.example.common.MainView
import platform.UIKit.UIApplication
import platform.UIKit.UIApplicationDelegateProtocol
import platform.UIKit.UIApplicationMain
import platform.UIKit.UIResponder
import platform.UIKit.UIScreen
import platform.

multiplatform-composeA demo to show usage of Jetbrains Compose in Android and iOS.项目地址:https://gitcode.com/gh_mirrors/mu/multiplatform-compose

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

滕骅照Fitzgerald

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值