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

Add BaselineProfiles for improving library performance #4

Merged
merged 6 commits into from
Jul 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions benchmark-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
64 changes: 64 additions & 0 deletions benchmark-app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import com.skydoves.orbitary.Configuration
import com.skydoves.orbitary.Dependencies
import com.skydoves.orbitary.Versions

plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}

android {
namespace 'com.skydoves.orbitary.benchmark.app'
compileSdk Configuration.compileSdk

defaultConfig {
applicationId "com.skydoves.orbitary.benchmark.app"
minSdk 23
targetSdk Configuration.targetSdk
}

buildFeatures {
compose true
buildConfig false
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

composeOptions {
kotlinCompilerExtensionVersion Versions.COMPOSE_COMPILER
}

kotlinOptions {
jvmTarget = '1.8'
}

packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}

lintOptions {
abortOnError false
}
buildTypes {
benchmark {
signingConfig signingConfigs.debug
matchingFallbacks = ['release']
debuggable false
}
}
}

dependencies {
implementation project(":orbitary")

implementation Dependencies.material
implementation Dependencies.composeUI
implementation Dependencies.composeActivity
implementation Dependencies.composeRuntime
implementation Dependencies.composeMaterial
}
28 changes: 28 additions & 0 deletions benchmark-app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.OrbitaryDemo">
<profileable
android:shell="true"
tools:targetApi="29" />

<activity
android:name=".MainActivity"
android:exported="true"
android:theme="@style/Theme.OrbitaryDemo">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Designed and developed by 2022 skydoves (Jaewoong Eum)
*
* 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
*
* http://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.
*/

package com.skydoves.orbitary.benchmark.app

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Column
import com.skydoves.orbitary.benchmark.app.profiles.OrbiraySharedElementTransitionProfiles
import com.skydoves.orbitary.benchmark.app.profiles.OrbitaryMovementProfiles
import com.skydoves.orbitary.benchmark.app.profiles.OrbitaryTransformationProfiles

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

setContent {
Column {
OrbitaryMovementProfiles()
OrbitaryTransformationProfiles()
OrbiraySharedElementTransitionProfiles()
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Designed and developed by 2022 skydoves (Jaewoong Eum)
*
* 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
*
* http://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.
*/

package com.skydoves.orbitary.benchmark.app.profiles

import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.SpringSpec
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.IntSize

val transformationSpec = SpringSpec<IntSize>(
dampingRatio = Spring.DampingRatioMediumBouncy,
stiffness = 200f
)

val movementSpec = SpringSpec<IntOffset>(
dampingRatio = Spring.DampingRatioMediumBouncy,
stiffness = 200f
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Designed and developed by 2022 skydoves (Jaewoong Eum)
*
* 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
*
* http://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.
*/

package com.skydoves.orbitary.benchmark.app.profiles

import androidx.compose.animation.core.SpringSpec
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.skydoves.orbitary.Orbitary
import com.skydoves.orbitary.animateSharedElementTransition
import com.skydoves.orbitary.rememberContentWithOrbitaryScope

@Composable
fun OrbiraySharedElementTransitionProfiles() {
var isTransformed by rememberSaveable { mutableStateOf(false) }
val item = rememberContentWithOrbitaryScope {
Box(
modifier = if (isTransformed) {
Modifier.fillMaxSize()
} else {
Modifier.size(60.dp, 60.dp)
}
.animateSharedElementTransition(
SpringSpec(stiffness = 500f),
SpringSpec(stiffness = 500f)
)
.background(Color.Yellow)
)
}

Orbitary(
modifier = Modifier
.fillMaxWidth()
.clickable { isTransformed = !isTransformed }
) {
if (isTransformed) {
Column(
horizontalAlignment = Alignment.End,
verticalArrangement = Arrangement.Center
) {
Box(
modifier = Modifier
.size(90.dp, 90.dp)
.background(Color.Blue)
)
}
} else {
Column(
Modifier.padding(20.dp),
) {
item()
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Designed and developed by 2022 skydoves (Jaewoong Eum)
*
* 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
*
* http://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.
*/

package com.skydoves.orbitary.benchmark.app.profiles

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.skydoves.orbitary.Orbitary
import com.skydoves.orbitary.animateMovement
import com.skydoves.orbitary.rememberContentWithOrbitaryScope

@Composable
fun OrbitaryMovementProfiles() {
var isTransformed by rememberSaveable { mutableStateOf(true) }
val item = rememberContentWithOrbitaryScope {
Box(
modifier = if (isTransformed) {
Modifier.size(60.dp, 60.dp)
} else {
Modifier.size(30.dp, 30.dp)
}
.background(Color.Green)
.animateMovement(movementSpec)
)
}

Orbitary(
modifier = Modifier
.padding(20.dp)
.fillMaxWidth()
.clickable { isTransformed = !isTransformed },
isTransformed = isTransformed,
onStartContent = {
Column(
horizontalAlignment = Alignment.Start,
verticalArrangement = Arrangement.Center
) {
item()
}
},
onTransformedContent = {
Column(
horizontalAlignment = Alignment.End,
verticalArrangement = Arrangement.Center
) {
item()
}
}
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Designed and developed by 2022 skydoves (Jaewoong Eum)
*
* 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
*
* http://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.
*/

package com.skydoves.orbitary.benchmark.app.profiles

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.skydoves.orbitary.Orbitary
import com.skydoves.orbitary.animateTransformation
import com.skydoves.orbitary.rememberContentWithOrbitaryScope

@Composable
fun OrbitaryTransformationProfiles() {
var isTransformed by rememberSaveable { mutableStateOf(false) }
val item = rememberContentWithOrbitaryScope {
Box(
modifier = if (isTransformed) {
Modifier.size(50.dp, 50.dp)
} else {
Modifier.size(20.dp, 20.dp)
}
.background(Color.Blue)
.animateTransformation(transformationSpec)
)
}

Orbitary(
modifier = Modifier
.clickable { isTransformed = !isTransformed }
) {
Column(
Modifier.padding(20.dp)
) {
item()
}
}
}
Loading