Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhamsinghshubham777 committed Sep 1, 2023
0 parents commit 3d72d7d
Show file tree
Hide file tree
Showing 39 changed files with 1,733 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

*.iml
.gradle
.idea
.DS_Store
build
*/build
captures
.externalNativeBuild
.cxx
local.properties
xcuserdata/
Pods/
*.jks
*yarn.lock
27 changes: 27 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Compose Multiplatform Application

## Before running!
- check your system with [KDoctor](https://github.com/Kotlin/kdoctor)
- install JDK 8 on your machine
- add `local.properties` file to the project root and set a path to Android SDK there
- run `./gradlew podInstall` in the project root

### Android
To run the application on android device/emulator:
- open project in Android Studio and run imported android run configuration

To build the application bundle:
- run `./gradlew :composeApp:assembleDebug`
- find `.apk` file in `composeApp/build/outputs/apk/debug/composeApp-debug.apk`

### Desktop
Run the desktop application: `./gradlew :composeApp:run`

### iOS
To run the application on iPhone device/simulator:
- Open `iosApp/iosApp.xcworkspace` in Xcode and run standard configuration
- Or use [Kotlin Multiplatform Mobile plugin](https://plugins.jetbrains.com/plugin/14936-kotlin-multiplatform-mobile) for Android Studio

### Browser
Run the browser application: `./gradlew :composeApp:jsBrowserDevelopmentRun`

39 changes: 39 additions & 0 deletions adapt/adapt.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Pod::Spec.new do |spec|
spec.name = 'adapt'
spec.version = '1.0.0'
spec.homepage = 'empty'
spec.source = { :http=> ''}
spec.authors = ''
spec.license = ''
spec.summary = 'Adapt UI library'
spec.vendored_frameworks = 'build/cocoapods/framework/adapt.framework'
spec.libraries = 'c++'
spec.ios.deployment_target = '11.0'


spec.pod_target_xcconfig = {
'KOTLIN_PROJECT_PATH' => ':adapt',
'PRODUCT_MODULE_NAME' => 'adapt',
}

spec.script_phases = [
{
:name => 'Build adapt',
:execution_position => :before_compile,
:shell_path => '/bin/sh',
:script => <<-SCRIPT
if [ "YES" = "$OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED" ]; then
echo "Skipping Gradle build task invocation due to OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED environment variable set to \"YES\""
exit 0
fi
set -ev
REPO_ROOT="$PODS_TARGET_SRCROOT"
"$REPO_ROOT/../gradlew" -p "$REPO_ROOT" $KOTLIN_PROJECT_PATH:syncFramework \
-Pkotlin.native.cocoapods.platform=$PLATFORM_NAME \
-Pkotlin.native.cocoapods.archs="$ARCHS" \
-Pkotlin.native.cocoapods.configuration="$CONFIGURATION"
SCRIPT
}
]
spec.resources = ['build/compose/ios/adapt/compose-resources']
end
119 changes: 119 additions & 0 deletions adapt/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import org.jetbrains.compose.desktop.application.dsl.TargetFormat

plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.cocoapods)
alias(libs.plugins.compose)
alias(libs.plugins.multiplatform)
}

@OptIn(org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi::class)
kotlin {
targetHierarchy.default()
androidTarget {
compilations.all {
kotlinOptions {
jvmTarget = "1.8"
}
}
}

jvm("desktop")

js {
browser()
binaries.executable()
}

iosX64()
iosArm64()
iosSimulatorArm64()

cocoapods {
version = "1.0.0"
summary = "Adapt UI library"
homepage = "empty"
ios.deploymentTarget = "11.0"
framework {
baseName = "adapt"
isStatic = true
}
}

sourceSets {
all {
languageSettings {
optIn("org.jetbrains.compose.resources.ExperimentalResourceApi")
}
}
val commonMain by getting {
dependencies {
@OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
implementation(compose.components.resources)
implementation(compose.foundation)
implementation(compose.material3)
implementation(compose.runtime)
implementation(compose.ui)
}
}

val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
}

val androidMain by getting {
dependencies {
implementation(compose.uiTooling)
implementation(compose.preview)
}
}
}
}

// TODO: Remove this when JetBrains Compose supports Kotlin 1.9.10
compose {
kotlinCompilerPlugin.set(dependencies.compiler.forKotlin("1.9.0"))
kotlinCompilerPluginArgs.add("suppressKotlinVersionCompatibilityCheck=1.9.10")
}

android {
namespace = "design.adapt"
compileSdk = 34

defaultConfig {
minSdk = 21
}
sourceSets["main"].apply {
manifest.srcFile("src/androidMain/AndroidManifest.xml")
res.srcDirs("src/androidMain/resources")
resources.srcDirs("src/commonMain/resources")
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
composeOptions {
kotlinCompilerExtensionVersion = libs.versions.compose.compiler.get()
}
buildFeatures {
compose = true
}
}

compose.desktop {
application {
mainClass = "MainKt"

nativeDistributions {
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
packageName = "design.adapt.desktopApp"
packageVersion = "1.0.0"
}
}
}

compose.experimental {
web.application {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package design.adapt.previews

import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import design.adapt.AdaptButton

@Preview
@Composable
fun AdaptButtonPreview() {
AdaptButton {
}
}
71 changes: 71 additions & 0 deletions adapt/src/commonMain/kotlin/design/adapt/AdaptButton.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package design.adapt

import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.spring
import androidx.compose.foundation.Indication
import androidx.compose.foundation.IndicationInstance
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.InteractionSource
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsPressedAsState
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Stable
import androidx.compose.runtime.State
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.drawscope.ContentDrawScope
import androidx.compose.ui.graphics.drawscope.scale
import androidx.compose.ui.unit.dp

@Composable
fun AdaptButton(
modifier: Modifier = Modifier,
onClick: () -> Unit,
) {
Text(
modifier = modifier
.clickable(
onClick = onClick,
interactionSource = remember { MutableInteractionSource() },
indication = remember { ScaleIndication() }
)
.clip(RoundedCornerShape(16.dp))
.background(MaterialTheme.colorScheme.primaryContainer)
.padding(16.dp),
text = "Adapt Button"
)
}

@Stable
class ScaleIndication : Indication {
@Composable
override fun rememberUpdatedInstance(interactionSource: InteractionSource): IndicationInstance {
val isPressed by interactionSource.collectIsPressedAsState()
val animatedScale = animateFloatAsState(
targetValue = if (isPressed) 0.93f else 1f,
animationSpec = spring(
dampingRatio = Spring.DampingRatioMediumBouncy,
stiffness = Spring.StiffnessMediumLow,
)
)
return remember {
ScaleIndicationInstance(scale = animatedScale)
}
}

class ScaleIndicationInstance(private val scale: State<Float>) : IndicationInstance {
override fun ContentDrawScope.drawIndication() {
scale(scale = scale.value) {
this@drawIndication.drawContent()
}
}
}
}
8 changes: 8 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
plugins {
alias(libs.plugins.android.application).apply(false)
alias(libs.plugins.android.library).apply(false)
alias(libs.plugins.cocoapods).apply(false)
alias(libs.plugins.compose).apply(false)
alias(libs.plugins.kotlin.android).apply(false)
alias(libs.plugins.multiplatform).apply(false)
}
90 changes: 90 additions & 0 deletions gradle.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@

@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=.
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%" == "0" goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

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%"=="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!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1

:mainEnd
if "%OS%"=="Windows_NT" endlocal

:omega
Loading

0 comments on commit 3d72d7d

Please sign in to comment.