diff --git a/compose/.gitignore b/compose/.gitignore new file mode 100644 index 00000000000..42105626e0b --- /dev/null +++ b/compose/.gitignore @@ -0,0 +1,17 @@ + +*.iml +.gradle +.idea +.kotlin +.DS_Store +build +*/build +captures +.externalNativeBuild +.cxx +local.properties +xcuserdata/ +Pods/ +*.jks +*.gpg +*yarn.lock diff --git a/compose/README.MD b/compose/README.MD new file mode 100644 index 00000000000..ff49b48100c --- /dev/null +++ b/compose/README.MD @@ -0,0 +1,35 @@ +# Fluent UI System Icons for Compose Multiplatform + +### Run the demo app + +Desktop `./gradlew :demo:run` +Web `./gradlew :demo:wasmJsBrowserDevelopmentRun` +Android `./gradlew :demo:assembleDebug` + +### Publish to MavenLocal + +1) Run `./gradlew :library:publishToMavenLocal` +2) Open `~/.m2/repository/com/microsoft/design/compose/` + +### Publish to MavenCentral + +1) Create an account and a namespace on Sonatype: + https://central.sonatype.org/register/central-portal/#create-an-account +2) Add developer id, name, email and the project url to + `./library/build.gradle.kts` +3) Generate a GPG key: + https://getstream.io/blog/publishing-libraries-to-mavencentral-2021/#generating-a-gpg-key-pair + ``` + gpg --full-gen-key + gpg --keyserver keyserver.ubuntu.com --send-keys XXXXXXXX + gpg --export-secret-key XXXXXXXX > XXXXXXXX.gpg + ``` +4) Add these lines to `gradle.properties`: + ``` + signing.keyId=XXXXXXXX + signing.password=[key password] + signing.secretKeyRingFile=../XXXXXXXX.gpg + mavenCentralUsername=[generated username] + mavenCentralPassword=[generated password] + ``` +5) Run `./gradlew :library:publishAndReleaseToMavenCentral --no-configuration-cache` diff --git a/compose/build.gradle.kts b/compose/build.gradle.kts new file mode 100644 index 00000000000..92086486427 --- /dev/null +++ b/compose/build.gradle.kts @@ -0,0 +1,8 @@ +plugins { + alias(libs.plugins.multiplatform).apply(false) + alias(libs.plugins.android.library).apply(false) + alias(libs.plugins.maven.publish).apply(false) + alias(libs.plugins.compose.compiler).apply(false) + alias(libs.plugins.compose).apply(false) + alias(libs.plugins.android.application).apply(false) +} diff --git a/compose/demo/build.gradle.kts b/compose/demo/build.gradle.kts new file mode 100644 index 00000000000..0540086da2c --- /dev/null +++ b/compose/demo/build.gradle.kts @@ -0,0 +1,81 @@ +import org.jetbrains.compose.desktop.application.dsl.TargetFormat.* + +plugins { + alias(libs.plugins.multiplatform) + alias(libs.plugins.compose.compiler) + alias(libs.plugins.compose) + alias(libs.plugins.android.application) +} + +kotlin { + androidTarget() + jvm() + js { + browser() + binaries.executable() + } + wasmJs { + browser() + binaries.executable() + } + listOf( + iosX64(), + iosArm64(), + iosSimulatorArm64() + ).forEach { + it.binaries.framework { + baseName = "ComposeApp" + isStatic = true + } + } + + sourceSets { + commonMain.dependencies { + implementation(compose.runtime) + implementation(compose.foundation) + implementation(compose.material3) + implementation(compose.components.resources) + + implementation(project(":library")) + } + + androidMain.dependencies { + implementation(libs.androidx.activityCompose) + } + + jvmMain.dependencies { + implementation(compose.desktop.currentOs) + } + + } +} + +android { + namespace = "com.microsoft.design.compose.demo" + compileSdk = 35 + + defaultConfig { + minSdk = 21 + targetSdk = 35 + + applicationId = "com.microsoft.design.compose.demo.androidApp" + versionCode = 1 + versionName = "1.0.0" + } +} + +compose.desktop { + application { + mainClass = "MainKt" + + nativeDistributions { + targetFormats(Dmg, Msi, Deb) + packageName = "Multiplatform App" + packageVersion = "1.0.0" + + macOS { + bundleID = "com.microsoft.design.compose.demo.desktopApp" + } + } + } +} diff --git a/compose/demo/src/androidMain/AndroidManifest.xml b/compose/demo/src/androidMain/AndroidManifest.xml new file mode 100644 index 00000000000..a98aebd9843 --- /dev/null +++ b/compose/demo/src/androidMain/AndroidManifest.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/compose/demo/src/androidMain/kotlin/com/microsoft/design/compose/demo/App.android.kt b/compose/demo/src/androidMain/kotlin/com/microsoft/design/compose/demo/App.android.kt new file mode 100644 index 00000000000..9ada32a593b --- /dev/null +++ b/compose/demo/src/androidMain/kotlin/com/microsoft/design/compose/demo/App.android.kt @@ -0,0 +1,14 @@ +package com.microsoft.design.compose.demo + +import android.os.Bundle +import androidx.activity.ComponentActivity +import androidx.activity.compose.setContent +import androidx.activity.enableEdgeToEdge + +class AppActivity : ComponentActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + enableEdgeToEdge() + setContent { App() } + } +} diff --git a/compose/demo/src/androidMain/kotlin/com/microsoft/design/compose/demo/theme/Theme.android.kt b/compose/demo/src/androidMain/kotlin/com/microsoft/design/compose/demo/theme/Theme.android.kt new file mode 100644 index 00000000000..b4cefaaf446 --- /dev/null +++ b/compose/demo/src/androidMain/kotlin/com/microsoft/design/compose/demo/theme/Theme.android.kt @@ -0,0 +1,19 @@ +package com.microsoft.design.compose.demo.theme + +import android.app.Activity +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.ui.platform.LocalView +import androidx.core.view.WindowInsetsControllerCompat + +@Composable +internal actual fun SystemAppearance(isDark: Boolean) { + val view = LocalView.current + LaunchedEffect(isDark) { + val window = (view.context as Activity).window + WindowInsetsControllerCompat(window, window.decorView).apply { + isAppearanceLightStatusBars = isDark + isAppearanceLightNavigationBars = isDark + } + } +} \ No newline at end of file diff --git a/compose/demo/src/androidMain/res/mipmap-anydpi-v26/ic_launcher.xml b/compose/demo/src/androidMain/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 00000000000..345888d26e6 --- /dev/null +++ b/compose/demo/src/androidMain/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/compose/demo/src/androidMain/res/mipmap-hdpi/ic_launcher.png b/compose/demo/src/androidMain/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 00000000000..fe557d6f20e Binary files /dev/null and b/compose/demo/src/androidMain/res/mipmap-hdpi/ic_launcher.png differ diff --git a/compose/demo/src/androidMain/res/mipmap-hdpi/ic_launcher_background.png b/compose/demo/src/androidMain/res/mipmap-hdpi/ic_launcher_background.png new file mode 100644 index 00000000000..1b4e1e47ed7 Binary files /dev/null and b/compose/demo/src/androidMain/res/mipmap-hdpi/ic_launcher_background.png differ diff --git a/compose/demo/src/androidMain/res/mipmap-hdpi/ic_launcher_foreground.png b/compose/demo/src/androidMain/res/mipmap-hdpi/ic_launcher_foreground.png new file mode 100644 index 00000000000..9b602b9f22b Binary files /dev/null and b/compose/demo/src/androidMain/res/mipmap-hdpi/ic_launcher_foreground.png differ diff --git a/compose/demo/src/androidMain/res/mipmap-hdpi/ic_launcher_monochrome.png b/compose/demo/src/androidMain/res/mipmap-hdpi/ic_launcher_monochrome.png new file mode 100644 index 00000000000..d8491850868 Binary files /dev/null and b/compose/demo/src/androidMain/res/mipmap-hdpi/ic_launcher_monochrome.png differ diff --git a/compose/demo/src/androidMain/res/mipmap-mdpi/ic_launcher.png b/compose/demo/src/androidMain/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 00000000000..c079af28a3e Binary files /dev/null and b/compose/demo/src/androidMain/res/mipmap-mdpi/ic_launcher.png differ diff --git a/compose/demo/src/androidMain/res/mipmap-mdpi/ic_launcher_background.png b/compose/demo/src/androidMain/res/mipmap-mdpi/ic_launcher_background.png new file mode 100644 index 00000000000..fac44bde7fd Binary files /dev/null and b/compose/demo/src/androidMain/res/mipmap-mdpi/ic_launcher_background.png differ diff --git a/compose/demo/src/androidMain/res/mipmap-mdpi/ic_launcher_foreground.png b/compose/demo/src/androidMain/res/mipmap-mdpi/ic_launcher_foreground.png new file mode 100644 index 00000000000..6823e999a38 Binary files /dev/null and b/compose/demo/src/androidMain/res/mipmap-mdpi/ic_launcher_foreground.png differ diff --git a/compose/demo/src/androidMain/res/mipmap-mdpi/ic_launcher_monochrome.png b/compose/demo/src/androidMain/res/mipmap-mdpi/ic_launcher_monochrome.png new file mode 100644 index 00000000000..5b63c843ff2 Binary files /dev/null and b/compose/demo/src/androidMain/res/mipmap-mdpi/ic_launcher_monochrome.png differ diff --git a/compose/demo/src/androidMain/res/mipmap-xhdpi/ic_launcher.png b/compose/demo/src/androidMain/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 00000000000..3ef239653fd Binary files /dev/null and b/compose/demo/src/androidMain/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/compose/demo/src/androidMain/res/mipmap-xhdpi/ic_launcher_background.png b/compose/demo/src/androidMain/res/mipmap-xhdpi/ic_launcher_background.png new file mode 100644 index 00000000000..efe105a1135 Binary files /dev/null and b/compose/demo/src/androidMain/res/mipmap-xhdpi/ic_launcher_background.png differ diff --git a/compose/demo/src/androidMain/res/mipmap-xhdpi/ic_launcher_foreground.png b/compose/demo/src/androidMain/res/mipmap-xhdpi/ic_launcher_foreground.png new file mode 100644 index 00000000000..98f4eeb5052 Binary files /dev/null and b/compose/demo/src/androidMain/res/mipmap-xhdpi/ic_launcher_foreground.png differ diff --git a/compose/demo/src/androidMain/res/mipmap-xhdpi/ic_launcher_monochrome.png b/compose/demo/src/androidMain/res/mipmap-xhdpi/ic_launcher_monochrome.png new file mode 100644 index 00000000000..ee450d82b97 Binary files /dev/null and b/compose/demo/src/androidMain/res/mipmap-xhdpi/ic_launcher_monochrome.png differ diff --git a/compose/demo/src/androidMain/res/mipmap-xxhdpi/ic_launcher.png b/compose/demo/src/androidMain/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 00000000000..883db5191be Binary files /dev/null and b/compose/demo/src/androidMain/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/compose/demo/src/androidMain/res/mipmap-xxhdpi/ic_launcher_background.png b/compose/demo/src/androidMain/res/mipmap-xxhdpi/ic_launcher_background.png new file mode 100644 index 00000000000..c42d5da0998 Binary files /dev/null and b/compose/demo/src/androidMain/res/mipmap-xxhdpi/ic_launcher_background.png differ diff --git a/compose/demo/src/androidMain/res/mipmap-xxhdpi/ic_launcher_foreground.png b/compose/demo/src/androidMain/res/mipmap-xxhdpi/ic_launcher_foreground.png new file mode 100644 index 00000000000..791b76044df Binary files /dev/null and b/compose/demo/src/androidMain/res/mipmap-xxhdpi/ic_launcher_foreground.png differ diff --git a/compose/demo/src/androidMain/res/mipmap-xxhdpi/ic_launcher_monochrome.png b/compose/demo/src/androidMain/res/mipmap-xxhdpi/ic_launcher_monochrome.png new file mode 100644 index 00000000000..7bf2180526c Binary files /dev/null and b/compose/demo/src/androidMain/res/mipmap-xxhdpi/ic_launcher_monochrome.png differ diff --git a/compose/demo/src/androidMain/res/mipmap-xxxhdpi/ic_launcher.png b/compose/demo/src/androidMain/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 00000000000..857d804665c Binary files /dev/null and b/compose/demo/src/androidMain/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/compose/demo/src/androidMain/res/mipmap-xxxhdpi/ic_launcher_background.png b/compose/demo/src/androidMain/res/mipmap-xxxhdpi/ic_launcher_background.png new file mode 100644 index 00000000000..f542a43b65d Binary files /dev/null and b/compose/demo/src/androidMain/res/mipmap-xxxhdpi/ic_launcher_background.png differ diff --git a/compose/demo/src/androidMain/res/mipmap-xxxhdpi/ic_launcher_foreground.png b/compose/demo/src/androidMain/res/mipmap-xxxhdpi/ic_launcher_foreground.png new file mode 100644 index 00000000000..7a102af32d8 Binary files /dev/null and b/compose/demo/src/androidMain/res/mipmap-xxxhdpi/ic_launcher_foreground.png differ diff --git a/compose/demo/src/androidMain/res/mipmap-xxxhdpi/ic_launcher_monochrome.png b/compose/demo/src/androidMain/res/mipmap-xxxhdpi/ic_launcher_monochrome.png new file mode 100644 index 00000000000..76fbc419c6d Binary files /dev/null and b/compose/demo/src/androidMain/res/mipmap-xxxhdpi/ic_launcher_monochrome.png differ diff --git a/compose/demo/src/commonMain/kotlin/com/microsoft/design/compose/demo/App.kt b/compose/demo/src/commonMain/kotlin/com/microsoft/design/compose/demo/App.kt new file mode 100644 index 00000000000..0bcdbee7958 --- /dev/null +++ b/compose/demo/src/commonMain/kotlin/com/microsoft/design/compose/demo/App.kt @@ -0,0 +1,94 @@ +package com.microsoft.design.compose.demo + +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.WindowInsets +import androidx.compose.foundation.layout.asPaddingValues +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.safeDrawing +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.windowInsetsPadding +import androidx.compose.foundation.lazy.grid.GridCells +import androidx.compose.foundation.lazy.grid.LazyVerticalGrid +import androidx.compose.foundation.text.selection.SelectionContainer +import androidx.compose.material3.AlertDialog +import androidx.compose.material3.Card +import androidx.compose.material3.Icon +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import androidx.compose.ui.window.Dialog +import com.microsoft.design.compose.demo.theme.AppTheme +import com.microsoft.design.compose.icons.Res +import com.microsoft.design.compose.icons.allDrawableResources +import org.jetbrains.compose.resources.DrawableResource +import org.jetbrains.compose.resources.painterResource + +@Composable +internal fun App() = AppTheme { + val allIcons: List> = remember { + Res.allDrawableResources.entries.filter { it.key.contains("24") }.sortedBy { it.key } + } + val (selectedIcon, setSelectedIcon) = remember { mutableStateOf?>(null) } + + LazyVerticalGrid( + columns = GridCells.Adaptive(80.dp), + modifier = Modifier.fillMaxSize(), + contentPadding = WindowInsets.safeDrawing.asPaddingValues(), + verticalArrangement = Arrangement.spacedBy(8.dp), + horizontalArrangement = Arrangement.spacedBy(8.dp), + ) { + items(allIcons.size) { + Column( + horizontalAlignment = Alignment.CenterHorizontally, + modifier = Modifier.clickable { + setSelectedIcon(allIcons[it]) + } + ) { + Icon( + modifier = Modifier.padding(8.dp).size(48.dp), + painter = painterResource(allIcons[it].value), + contentDescription = allIcons[it].key, + ) + Text( + modifier = Modifier.padding(8.dp), + maxLines = 1, + text = allIcons[it].key.removePrefix("ic_fluent_") + ) + } + } + } + + if (selectedIcon != null) { + Dialog( + onDismissRequest = { setSelectedIcon(null) } + ) { + Card { + Row( + verticalAlignment = Alignment.CenterVertically, + ) { + Icon( + modifier = Modifier.padding(8.dp).size(48.dp), + painter = painterResource(selectedIcon.value), + contentDescription = selectedIcon.key, + ) + SelectionContainer { + Text( + modifier = Modifier.padding(8.dp), + text = selectedIcon.key + ) + } + } + } + } + } +} diff --git a/compose/demo/src/commonMain/kotlin/com/microsoft/design/compose/demo/theme/Color.kt b/compose/demo/src/commonMain/kotlin/com/microsoft/design/compose/demo/theme/Color.kt new file mode 100644 index 00000000000..db2c2aff70e --- /dev/null +++ b/compose/demo/src/commonMain/kotlin/com/microsoft/design/compose/demo/theme/Color.kt @@ -0,0 +1,80 @@ +package com.microsoft.design.compose.demo.theme + +import androidx.compose.ui.graphics.Color + +//generated by https://materialkolor.com +//Color palette was taken here: https://coolors.co/palette/e63946-f1faee-a8dadc-457b9d-1d3557 + +internal val Seed = Color(0xFF1D3557) + +internal val PrimaryLight = Color(0xFF485F84) +internal val OnPrimaryLight = Color(0xFFFFFFFF) +internal val PrimaryContainerLight = Color(0xFFD5E3FF) +internal val OnPrimaryContainerLight = Color(0xFF30476A) +internal val SecondaryLight = Color(0xFF2B6485) +internal val OnSecondaryLight = Color(0xFFFFFFFF) +internal val SecondaryContainerLight = Color(0xFFC7E7FF) +internal val OnSecondaryContainerLight = Color(0xFF064C6B) +internal val TertiaryLight = Color(0xFF356668) +internal val OnTertiaryLight = Color(0xFFFFFFFF) +internal val TertiaryContainerLight = Color(0xFFB9ECEE) +internal val OnTertiaryContainerLight = Color(0xFF1A4E50) +internal val ErrorLight = Color(0xFFBB152C) +internal val OnErrorLight = Color(0xFFFFFFFF) +internal val ErrorContainerLight = Color(0xFFFFDAD8) +internal val OnErrorContainerLight = Color(0xFF410007) +internal val BackgroundLight = Color(0xFFF9F9F9) +internal val OnBackgroundLight = Color(0xFF1A1C1C) +internal val SurfaceLight = Color(0xFFF9F9F9) +internal val OnSurfaceLight = Color(0xFF1A1C1C) +internal val SurfaceVariantLight = Color(0xFFDCE5D9) +internal val OnSurfaceVariantLight = Color(0xFF404941) +internal val OutlineLight = Color(0xFF717970) +internal val OutlineVariantLight = Color(0xFFC0C9BE) +internal val ScrimLight = Color(0xFF000000) +internal val InverseSurfaceLight = Color(0xFF2F3131) +internal val InverseOnSurfaceLight = Color(0xFFF0F1F1) +internal val InversePrimaryLight = Color(0xFFB0C7F1) +internal val SurfaceDimLight = Color(0xFFDADADA) +internal val SurfaceBrightLight = Color(0xFFF9F9F9) +internal val SurfaceContainerLowestLight = Color(0xFFFFFFFF) +internal val SurfaceContainerLowLight = Color(0xFFF3F3F4) +internal val SurfaceContainerLight = Color(0xFFEEEEEE) +internal val SurfaceContainerHighLight = Color(0xFFE8E8E8) +internal val SurfaceContainerHighestLight = Color(0xFFE2E2E2) + +internal val PrimaryDark = Color(0xFFB0C7F1) +internal val OnPrimaryDark = Color(0xFF183153) +internal val PrimaryContainerDark = Color(0xFF30476A) +internal val OnPrimaryContainerDark = Color(0xFFD5E3FF) +internal val SecondaryDark = Color(0xFF98CDF2) +internal val OnSecondaryDark = Color(0xFF00344C) +internal val SecondaryContainerDark = Color(0xFF064C6B) +internal val OnSecondaryContainerDark = Color(0xFFC7E7FF) +internal val TertiaryDark = Color(0xFF9ECFD1) +internal val OnTertiaryDark = Color(0xFF003739) +internal val TertiaryContainerDark = Color(0xFF1A4E50) +internal val OnTertiaryContainerDark = Color(0xFFB9ECEE) +internal val ErrorDark = Color(0xFFFFB3B1) +internal val OnErrorDark = Color(0xFF680011) +internal val ErrorContainerDark = Color(0xFF92001C) +internal val OnErrorContainerDark = Color(0xFFFFDAD8) +internal val BackgroundDark = Color(0xFF121414) +internal val OnBackgroundDark = Color(0xFFE2E2E2) +internal val SurfaceDark = Color(0xFF121414) +internal val OnSurfaceDark = Color(0xFFE2E2E2) +internal val SurfaceVariantDark = Color(0xFF404941) +internal val OnSurfaceVariantDark = Color(0xFFC0C9BE) +internal val OutlineDark = Color(0xFF8A9389) +internal val OutlineVariantDark = Color(0xFF404941) +internal val ScrimDark = Color(0xFF000000) +internal val InverseSurfaceDark = Color(0xFFE2E2E2) +internal val InverseOnSurfaceDark = Color(0xFF2F3131) +internal val InversePrimaryDark = Color(0xFF485F84) +internal val SurfaceDimDark = Color(0xFF121414) +internal val SurfaceBrightDark = Color(0xFF37393A) +internal val SurfaceContainerLowestDark = Color(0xFF0C0F0F) +internal val SurfaceContainerLowDark = Color(0xFF1A1C1C) +internal val SurfaceContainerDark = Color(0xFF1E2020) +internal val SurfaceContainerHighDark = Color(0xFF282A2B) +internal val SurfaceContainerHighestDark = Color(0xFF333535) diff --git a/compose/demo/src/commonMain/kotlin/com/microsoft/design/compose/demo/theme/Theme.kt b/compose/demo/src/commonMain/kotlin/com/microsoft/design/compose/demo/theme/Theme.kt new file mode 100644 index 00000000000..84335514eda --- /dev/null +++ b/compose/demo/src/commonMain/kotlin/com/microsoft/design/compose/demo/theme/Theme.kt @@ -0,0 +1,107 @@ +package com.microsoft.design.compose.demo.theme + +import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Surface +import androidx.compose.material3.darkColorScheme +import androidx.compose.material3.lightColorScheme +import androidx.compose.runtime.* + +private val LightColorScheme = lightColorScheme( + primary = PrimaryLight, + onPrimary = OnPrimaryLight, + primaryContainer = PrimaryContainerLight, + onPrimaryContainer = OnPrimaryContainerLight, + secondary = SecondaryLight, + onSecondary = OnSecondaryLight, + secondaryContainer = SecondaryContainerLight, + onSecondaryContainer = OnSecondaryContainerLight, + tertiary = TertiaryLight, + onTertiary = OnTertiaryLight, + tertiaryContainer = TertiaryContainerLight, + onTertiaryContainer = OnTertiaryContainerLight, + error = ErrorLight, + onError = OnErrorLight, + errorContainer = ErrorContainerLight, + onErrorContainer = OnErrorContainerLight, + background = BackgroundLight, + onBackground = OnBackgroundLight, + surface = SurfaceLight, + onSurface = OnSurfaceLight, + surfaceVariant = SurfaceVariantLight, + onSurfaceVariant = OnSurfaceVariantLight, + outline = OutlineLight, + outlineVariant = OutlineVariantLight, + scrim = ScrimLight, + inverseSurface = InverseSurfaceLight, + inverseOnSurface = InverseOnSurfaceLight, + inversePrimary = InversePrimaryLight, + surfaceDim = SurfaceDimLight, + surfaceBright = SurfaceBrightLight, + surfaceContainerLowest = SurfaceContainerLowestLight, + surfaceContainerLow = SurfaceContainerLowLight, + surfaceContainer = SurfaceContainerLight, + surfaceContainerHigh = SurfaceContainerHighLight, + surfaceContainerHighest = SurfaceContainerHighestLight, +) + +private val DarkColorScheme = darkColorScheme( + primary = PrimaryDark, + onPrimary = OnPrimaryDark, + primaryContainer = PrimaryContainerDark, + onPrimaryContainer = OnPrimaryContainerDark, + secondary = SecondaryDark, + onSecondary = OnSecondaryDark, + secondaryContainer = SecondaryContainerDark, + onSecondaryContainer = OnSecondaryContainerDark, + tertiary = TertiaryDark, + onTertiary = OnTertiaryDark, + tertiaryContainer = TertiaryContainerDark, + onTertiaryContainer = OnTertiaryContainerDark, + error = ErrorDark, + onError = OnErrorDark, + errorContainer = ErrorContainerDark, + onErrorContainer = OnErrorContainerDark, + background = BackgroundDark, + onBackground = OnBackgroundDark, + surface = SurfaceDark, + onSurface = OnSurfaceDark, + surfaceVariant = SurfaceVariantDark, + onSurfaceVariant = OnSurfaceVariantDark, + outline = OutlineDark, + outlineVariant = OutlineVariantDark, + scrim = ScrimDark, + inverseSurface = InverseSurfaceDark, + inverseOnSurface = InverseOnSurfaceDark, + inversePrimary = InversePrimaryDark, + surfaceDim = SurfaceDimDark, + surfaceBright = SurfaceBrightDark, + surfaceContainerLowest = SurfaceContainerLowestDark, + surfaceContainerLow = SurfaceContainerLowDark, + surfaceContainer = SurfaceContainerDark, + surfaceContainerHigh = SurfaceContainerHighDark, + surfaceContainerHighest = SurfaceContainerHighestDark, +) + +internal val LocalThemeIsDark = compositionLocalOf { mutableStateOf(true) } + +@Composable +internal fun AppTheme( + content: @Composable () -> Unit +) { + val systemIsDark = isSystemInDarkTheme() + val isDarkState = remember(systemIsDark) { mutableStateOf(systemIsDark) } + CompositionLocalProvider( + LocalThemeIsDark provides isDarkState + ) { + val isDark by isDarkState + SystemAppearance(!isDark) + MaterialTheme( + colorScheme = if (isDark) DarkColorScheme else LightColorScheme, + content = { Surface(content = content) } + ) + } +} + +@Composable +internal expect fun SystemAppearance(isDark: Boolean) diff --git a/compose/demo/src/iosMain/kotlin/com/microsoft/design/compose/demo/theme/Theme.ios.kt b/compose/demo/src/iosMain/kotlin/com/microsoft/design/compose/demo/theme/Theme.ios.kt new file mode 100644 index 00000000000..faee975b89f --- /dev/null +++ b/compose/demo/src/iosMain/kotlin/com/microsoft/design/compose/demo/theme/Theme.ios.kt @@ -0,0 +1,17 @@ +package com.microsoft.design.compose.demo.theme + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import platform.UIKit.UIApplication +import platform.UIKit.UIStatusBarStyleDarkContent +import platform.UIKit.UIStatusBarStyleLightContent +import platform.UIKit.setStatusBarStyle + +@Composable +internal actual fun SystemAppearance(isDark: Boolean) { + LaunchedEffect(isDark) { + UIApplication.sharedApplication.setStatusBarStyle( + if (isDark) UIStatusBarStyleDarkContent else UIStatusBarStyleLightContent + ) + } +} \ No newline at end of file diff --git a/compose/demo/src/iosMain/kotlin/main.kt b/compose/demo/src/iosMain/kotlin/main.kt new file mode 100644 index 00000000000..448cb543612 --- /dev/null +++ b/compose/demo/src/iosMain/kotlin/main.kt @@ -0,0 +1,5 @@ +import androidx.compose.ui.window.ComposeUIViewController +import com.microsoft.design.compose.demo.App +import platform.UIKit.UIViewController + +fun MainViewController(): UIViewController = ComposeUIViewController { App() } diff --git a/compose/demo/src/jsMain/kotlin/com/microsoft/design/compose/demo/theme/Theme.js.kt b/compose/demo/src/jsMain/kotlin/com/microsoft/design/compose/demo/theme/Theme.js.kt new file mode 100644 index 00000000000..6fd54dbe451 --- /dev/null +++ b/compose/demo/src/jsMain/kotlin/com/microsoft/design/compose/demo/theme/Theme.js.kt @@ -0,0 +1,7 @@ +package com.microsoft.design.compose.demo.theme + +import androidx.compose.runtime.Composable + +@Composable +internal actual fun SystemAppearance(isDark: Boolean) { +} \ No newline at end of file diff --git a/compose/demo/src/jsMain/kotlin/main.kt b/compose/demo/src/jsMain/kotlin/main.kt new file mode 100644 index 00000000000..eaf83b401ce --- /dev/null +++ b/compose/demo/src/jsMain/kotlin/main.kt @@ -0,0 +1,15 @@ +import androidx.compose.ui.ExperimentalComposeUiApi +import androidx.compose.ui.window.ComposeViewport +import com.microsoft.design.compose.demo.App +import org.jetbrains.skiko.wasm.onWasmReady +import kotlinx.browser.document + +@OptIn(ExperimentalComposeUiApi::class) +fun main() { + onWasmReady { + val body = document.body ?: return@onWasmReady + ComposeViewport(body) { + App() + } + } +} diff --git a/compose/demo/src/jsMain/resources/index.html b/compose/demo/src/jsMain/resources/index.html new file mode 100644 index 00000000000..96a1f7abb87 --- /dev/null +++ b/compose/demo/src/jsMain/resources/index.html @@ -0,0 +1,20 @@ + + + + + Multiplatform App + + + + + + diff --git a/compose/demo/src/jvmMain/kotlin/com/microsoft/design/compose/demo/theme/Theme.jvm.kt b/compose/demo/src/jvmMain/kotlin/com/microsoft/design/compose/demo/theme/Theme.jvm.kt new file mode 100644 index 00000000000..6fd54dbe451 --- /dev/null +++ b/compose/demo/src/jvmMain/kotlin/com/microsoft/design/compose/demo/theme/Theme.jvm.kt @@ -0,0 +1,7 @@ +package com.microsoft.design.compose.demo.theme + +import androidx.compose.runtime.Composable + +@Composable +internal actual fun SystemAppearance(isDark: Boolean) { +} \ No newline at end of file diff --git a/compose/demo/src/jvmMain/kotlin/main.kt b/compose/demo/src/jvmMain/kotlin/main.kt new file mode 100644 index 00000000000..a945607b095 --- /dev/null +++ b/compose/demo/src/jvmMain/kotlin/main.kt @@ -0,0 +1,18 @@ +import androidx.compose.ui.unit.dp +import androidx.compose.ui.window.Window +import androidx.compose.ui.window.application +import androidx.compose.ui.window.rememberWindowState +import java.awt.Dimension +import com.microsoft.design.compose.demo.App + +fun main() = application { + Window( + title = "Multiplatform App", + state = rememberWindowState(width = 800.dp, height = 600.dp), + onCloseRequest = ::exitApplication, + ) { + window.minimumSize = Dimension(350, 600) + App() + } +} + diff --git a/compose/demo/src/wasmJsMain/kotlin/com/microsoft/design/compose/demo/theme/Theme.wasmJs.kt b/compose/demo/src/wasmJsMain/kotlin/com/microsoft/design/compose/demo/theme/Theme.wasmJs.kt new file mode 100644 index 00000000000..6fd54dbe451 --- /dev/null +++ b/compose/demo/src/wasmJsMain/kotlin/com/microsoft/design/compose/demo/theme/Theme.wasmJs.kt @@ -0,0 +1,7 @@ +package com.microsoft.design.compose.demo.theme + +import androidx.compose.runtime.Composable + +@Composable +internal actual fun SystemAppearance(isDark: Boolean) { +} \ No newline at end of file diff --git a/compose/demo/src/wasmJsMain/kotlin/main.kt b/compose/demo/src/wasmJsMain/kotlin/main.kt new file mode 100644 index 00000000000..0343df76aae --- /dev/null +++ b/compose/demo/src/wasmJsMain/kotlin/main.kt @@ -0,0 +1,12 @@ +import androidx.compose.ui.ExperimentalComposeUiApi +import androidx.compose.ui.window.ComposeViewport +import com.microsoft.design.compose.demo.App +import kotlinx.browser.document + +@OptIn(ExperimentalComposeUiApi::class) +fun main() { + val body = document.body ?: return + ComposeViewport(body) { + App() + } +} diff --git a/compose/demo/src/wasmJsMain/resources/index.html b/compose/demo/src/wasmJsMain/resources/index.html new file mode 100644 index 00000000000..5179ea74d8f --- /dev/null +++ b/compose/demo/src/wasmJsMain/resources/index.html @@ -0,0 +1,20 @@ + + + + + + Multiplatform App + + + + + diff --git a/compose/gradle.properties b/compose/gradle.properties new file mode 100644 index 00000000000..f4ea80f74b4 --- /dev/null +++ b/compose/gradle.properties @@ -0,0 +1,18 @@ +#Gradle +org.gradle.jvmargs=-Xmx8G +org.gradle.caching=true +org.gradle.configuration-cache=true +org.gradle.daemon=true +org.gradle.parallel=true + +#Kotlin +kotlin.code.style=official +kotlin.daemon.jvmargs=-Xmx8G +kotlin.native.binary.gc=cms + +#Android +android.useAndroidX=true +android.nonTransitiveRClass=true + +#Compose +org.jetbrains.compose.experimental.jscanvas.enabled=true diff --git a/compose/gradle/libs.versions.toml b/compose/gradle/libs.versions.toml new file mode 100644 index 00000000000..20685d33ab8 --- /dev/null +++ b/compose/gradle/libs.versions.toml @@ -0,0 +1,20 @@ +[versions] + +kotlin = "2.1.21" +agp = "8.9.3" +maven-publish = "0.32.0" +compose = "1.8.1" +androidx-activityCompose = "1.10.1" + +[libraries] + +androidx-activityCompose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activityCompose" } + +[plugins] + +multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } +android-library = { id = "com.android.library", version.ref = "agp" } +maven-publish = { id = "com.vanniktech.maven.publish", version.ref = "maven-publish" } +compose = { id = "org.jetbrains.compose", version.ref = "compose" } +compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } +android-application = { id = "com.android.application", version.ref = "agp" } diff --git a/compose/gradle/wrapper/gradle-wrapper.jar b/compose/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000000..e6441136f3d Binary files /dev/null and b/compose/gradle/wrapper/gradle-wrapper.jar differ diff --git a/compose/gradle/wrapper/gradle-wrapper.properties b/compose/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000000..002b867c48b --- /dev/null +++ b/compose/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.1-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/compose/gradlew b/compose/gradlew new file mode 100755 index 00000000000..1aa94a42690 --- /dev/null +++ b/compose/gradlew @@ -0,0 +1,249 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/compose/gradlew.bat b/compose/gradlew.bat new file mode 100644 index 00000000000..25da30dbdee --- /dev/null +++ b/compose/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/compose/library/build.gradle.kts b/compose/library/build.gradle.kts new file mode 100644 index 00000000000..b1a5b7f42b1 --- /dev/null +++ b/compose/library/build.gradle.kts @@ -0,0 +1,119 @@ +import com.vanniktech.maven.publish.SonatypeHost + +plugins { + alias(libs.plugins.multiplatform) + alias(libs.plugins.android.library) + alias(libs.plugins.maven.publish) + alias(libs.plugins.compose.compiler) + alias(libs.plugins.compose) +} + +kotlin { + androidTarget { publishLibraryVariants("release") } + jvm() + js { browser() } + wasmJs { browser() } + iosX64() + iosArm64() + iosSimulatorArm64() + + sourceSets { + commonMain.dependencies { + implementation(compose.runtime) + implementation(compose.components.resources) + } + } + +} + +android { + namespace = "com.microsoft.fluent.compose.icons" + compileSdk = 35 + + defaultConfig { + minSdk = 21 + } +} + +val copyAndroidVectorIcons = tasks.register("copyAndroidVectorIcons", CopyAndroidIcons::class) { + srcDir = rootProject.projectDir.resolve("../android/library/src/main/res/drawable") + destDir = layout.buildDirectory.dir("genComposeResources/drawable") +} + +compose.resources { + publicResClass = true + packageOfResClass = "com.microsoft.design.compose.icons" + customDirectory( + sourceSetName = "commonMain", + directoryProvider = copyAndroidVectorIcons.map { it.destDir.dir("..").get() } + ) +} + +abstract class CopyAndroidIcons : DefaultTask() { + @get:InputDirectory + abstract val srcDir: DirectoryProperty + + @get:OutputDirectory + abstract val destDir: DirectoryProperty + + data class IconInfo(val id: String, val type: String, val size: Int, val file: File) + + @TaskAction + fun run() { + val out = destDir.get().asFile + out.deleteRecursively() + out.mkdirs() + + val icons = srcDir.get().asFile.listFiles().orEmpty() + .filter { f -> f.isFile && f.extension == "xml" } + .map { f -> + f.nameWithoutExtension.split("_").let { parts -> + val type = parts.last() + val size = parts[parts.size - 2].toInt() + IconInfo(f.nameWithoutExtension.substringBefore("_${size}_$type"), type, size, f) + } + } + .filterNot { i -> i.type == "selector" } + .map { it.file } + icons.forEach { file -> + logger.info("Copying ${file.name}") + val icon = file.copyTo(out.resolve(file.name), overwrite = true) + icon.writeText( + icon.readText().replace("@color/fluent_default_icon_tint", "#000000") + ) + } + } +} + +//Publishing your Kotlin Multiplatform library to Maven Central +//https://www.jetbrains.com/help/kotlin-multiplatform-dev/multiplatform-publish-libraries.html +mavenPublishing { + publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL) + coordinates("com.microsoft.design.compose", "fluent-system-icons", "1.0.0") + + pom { + name = "Fluent UI System Icons" + description = "Fluent UI System Icons for Compose Multiplatform" + url = "https://github.com/microsoft/fluentui-system-icons" + + licenses { + license { + name = "MIT" + url = "https://opensource.org/licenses/MIT" + } + } + + developers { + developer { + id = "" //todo + name = "" //todo + email = "" //todo + } + } + + scm { + url = "https://github.com/microsoft/fluentui-system-icons" + } + } + if (project.hasProperty("signing.keyId")) signAllPublications() +} diff --git a/compose/settings.gradle.kts b/compose/settings.gradle.kts new file mode 100644 index 00000000000..c12d1dfb1d5 --- /dev/null +++ b/compose/settings.gradle.kts @@ -0,0 +1,30 @@ +pluginManagement { + repositories { + google { + content { + includeGroupByRegex("com\\.android.*") + includeGroupByRegex("com\\.google.*") + includeGroupByRegex("androidx.*") + includeGroupByRegex("android.*") + } + } + gradlePluginPortal() + mavenCentral() + } +} + +dependencyResolutionManagement { + repositories { + google { + content { + includeGroupByRegex("com\\.android.*") + includeGroupByRegex("com\\.google.*") + includeGroupByRegex("androidx.*") + includeGroupByRegex("android.*") + } + } + mavenCentral() + } +} +include(":library") +include(":demo")