-
Notifications
You must be signed in to change notification settings - Fork 1.9k
feat: add basic wrapping to support compose #2201
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
Open
Lyokone
wants to merge
4
commits into
feat/migrate-to-kotlin
Choose a base branch
from
feat/compose-wrapping
base: feat/migrate-to-kotlin
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,45 +1,53 @@ | ||||||||||||||||||
// NOTE: this project uses Gradle Kotlin DSL. More common build.gradle instructions can be found in | ||||||||||||||||||
// the main README. | ||||||||||||||||||
plugins { | ||||||||||||||||||
id("com.android.application") | ||||||||||||||||||
id("com.android.application") | ||||||||||||||||||
id("org.jetbrains.kotlin.android") | ||||||||||||||||||
id("org.jetbrains.kotlin.plugin.compose") | ||||||||||||||||||
id("org.jetbrains.compose") | ||||||||||||||||||
id("com.google.gms.google-services") | ||||||||||||||||||
id("kotlin-kapt") // ← kapt drives annotation processors | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
android { | ||||||||||||||||||
namespace = "com.firebase.uidemo" | ||||||||||||||||||
compileSdk = Config.SdkVersions.compile | ||||||||||||||||||
|
||||||||||||||||||
namespace = "com.firebase.uidemo" | ||||||||||||||||||
|
||||||||||||||||||
defaultConfig { | ||||||||||||||||||
minSdk = Config.SdkVersions.min | ||||||||||||||||||
targetSdk = Config.SdkVersions.target | ||||||||||||||||||
|
||||||||||||||||||
versionName = Config.version | ||||||||||||||||||
versionCode = 1 | ||||||||||||||||||
|
||||||||||||||||||
minSdk = Config.SdkVersions.min | ||||||||||||||||||
targetSdk = Config.SdkVersions.target | ||||||||||||||||||
versionName = Config.version | ||||||||||||||||||
versionCode = 1 | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's get rid of all the extra whitespaces (across all files) - I don't think it's common to use this formatting in Kotlin (at least I've never seen before)
Suggested change
|
||||||||||||||||||
multiDexEnabled = true | ||||||||||||||||||
resourcePrefix("fui_") | ||||||||||||||||||
vectorDrawables.useSupportLibrary = true | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
defaultConfig { | ||||||||||||||||||
multiDexEnabled = true | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
buildTypes { | ||||||||||||||||||
named("release").configure { | ||||||||||||||||||
release { | ||||||||||||||||||
// For the purposes of the sample, allow testing of a proguarded release build | ||||||||||||||||||
// using the debug key | ||||||||||||||||||
signingConfig = signingConfigs["debug"] | ||||||||||||||||||
|
||||||||||||||||||
postprocessing { | ||||||||||||||||||
isRemoveUnusedCode = true | ||||||||||||||||||
isRemoveUnusedCode = true | ||||||||||||||||||
isRemoveUnusedResources = true | ||||||||||||||||||
isObfuscate = true | ||||||||||||||||||
isOptimizeCode = true | ||||||||||||||||||
isObfuscate = true | ||||||||||||||||||
isOptimizeCode = true | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
lint { | ||||||||||||||||||
compileOptions { | ||||||||||||||||||
sourceCompatibility = JavaVersion.VERSION_17 | ||||||||||||||||||
targetCompatibility = JavaVersion.VERSION_17 | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
buildFeatures { | ||||||||||||||||||
viewBinding = true | ||||||||||||||||||
compose = true | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
lint { | ||||||||||||||||||
// Common lint options across all modules | ||||||||||||||||||
|
||||||||||||||||||
disable += mutableSetOf( | ||||||||||||||||||
|
@@ -59,16 +67,7 @@ android { | |||||||||||||||||
abortOnError = true | ||||||||||||||||||
|
||||||||||||||||||
baseline = file("$rootDir/library/quality/lint-baseline.xml") | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
compileOptions { | ||||||||||||||||||
sourceCompatibility = JavaVersion.VERSION_17 | ||||||||||||||||||
targetCompatibility = JavaVersion.VERSION_17 | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
buildFeatures { | ||||||||||||||||||
viewBinding = true | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
dependencies { | ||||||||||||||||||
|
@@ -80,23 +79,33 @@ dependencies { | |||||||||||||||||
implementation(project(":database")) | ||||||||||||||||||
implementation(project(":storage")) | ||||||||||||||||||
|
||||||||||||||||||
implementation(Config.Libs.Misc.glide) | ||||||||||||||||||
kapt(Config.Libs.Misc.glideCompiler) | ||||||||||||||||||
|
||||||||||||||||||
implementation(Config.Libs.Provider.facebook) | ||||||||||||||||||
// Needed to override Facebook | ||||||||||||||||||
implementation(Config.Libs.Androidx.cardView) | ||||||||||||||||||
implementation(Config.Libs.Androidx.cardView) | ||||||||||||||||||
implementation(Config.Libs.Androidx.customTabs) | ||||||||||||||||||
|
||||||||||||||||||
implementation(Config.Libs.Misc.glide) | ||||||||||||||||||
annotationProcessor(Config.Libs.Misc.glideCompiler) | ||||||||||||||||||
|
||||||||||||||||||
// Used for FirestorePagingActivity | ||||||||||||||||||
implementation(Config.Libs.Androidx.paging) | ||||||||||||||||||
|
||||||||||||||||||
// The following dependencies are not required to use the Firebase UI library. | ||||||||||||||||||
// They are used to make some aspects of the demo app implementation simpler for | ||||||||||||||||||
// demonstrative purposes, and you may find them useful in your own apps; YMMV. | ||||||||||||||||||
|
||||||||||||||||||
implementation(Config.Libs.Misc.permissions) | ||||||||||||||||||
implementation(Config.Libs.Androidx.constraint) | ||||||||||||||||||
debugImplementation(Config.Libs.Misc.leakCanary) | ||||||||||||||||||
|
||||||||||||||||||
val composeBom = platform("androidx.compose:compose-bom:2025.02.00") | ||||||||||||||||||
implementation(composeBom) | ||||||||||||||||||
androidTestImplementation(composeBom) | ||||||||||||||||||
|
||||||||||||||||||
implementation("androidx.compose.material3:material3") | ||||||||||||||||||
implementation("androidx.activity:activity-compose:1.10.0") | ||||||||||||||||||
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.8.5") | ||||||||||||||||||
debugImplementation("androidx.compose.ui:ui-tooling") | ||||||||||||||||||
releaseImplementation("androidx.compose.ui:ui-tooling-preview") | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
apply(plugin = "com.google.gms.google-services") | ||||||||||||||||||
kapt { correctErrorTypes = true } // optional but avoids some kapt warnings |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
app/src/main/java/com/firebase/uidemo/auth/compose/AuthComposeActivity.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.firebase.uidemo.auth.compose | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import android.os.Bundle | ||
import androidx.activity.ComponentActivity | ||
import androidx.activity.compose.setContent | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Surface | ||
import androidx.compose.ui.Modifier | ||
import com.firebase.ui.auth.AuthUI | ||
import com.firebase.ui.auth.data.model.FirebaseAuthUIAuthenticationResult | ||
import com.firebase.uidemo.R | ||
import com.firebase.uidemo.auth.SignedInActivity | ||
import com.firebase.uidemo.ui.theme.FirebaseUIDemoTheme | ||
|
||
class AuthComposeActivity : ComponentActivity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContent { | ||
FirebaseUIDemoTheme { | ||
Surface( | ||
modifier = Modifier.fillMaxSize(), | ||
color = MaterialTheme.colorScheme.background | ||
) { | ||
AuthScreen { result -> | ||
handleSignInResponse(result) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun handleSignInResponse(result: FirebaseAuthUIAuthenticationResult) { | ||
when (result.resultCode) { | ||
RESULT_OK -> { | ||
// Successfully signed in | ||
val response = result.idpResponse | ||
startActivity(SignedInActivity.createIntent(this, response)) | ||
finish() | ||
} | ||
else -> { | ||
// Sign in failed | ||
val response = result.idpResponse | ||
if (response == null) { | ||
// User pressed back button | ||
return | ||
} | ||
// Handle other error cases | ||
} | ||
} | ||
} | ||
|
||
companion object { | ||
fun createIntent(context: Context): Intent { | ||
return Intent(context, AuthComposeActivity::class.java) | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
app/src/main/java/com/firebase/uidemo/auth/compose/AuthScreen.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.firebase.uidemo.auth.compose | ||
|
||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.material3.CircularProgressIndicator | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import com.firebase.ui.auth.AuthUI | ||
import com.firebase.ui.auth.AuthUI.IdpConfig | ||
import com.firebase.ui.auth.data.model.FirebaseAuthUIAuthenticationResult | ||
import com.firebase.ui.auth.compose.FirebaseAuthUI | ||
import com.firebase.uidemo.R | ||
import com.google.firebase.auth.EmailAuthProvider | ||
import com.google.firebase.auth.GoogleAuthProvider | ||
|
||
@Composable | ||
fun AuthScreen( | ||
onSignInResult: (FirebaseAuthUIAuthenticationResult) -> Unit | ||
) { | ||
val providers = listOf( | ||
IdpConfig.GoogleBuilder().build(), | ||
IdpConfig.EmailBuilder().build() | ||
) | ||
|
||
Box( | ||
modifier = Modifier.fillMaxSize(), | ||
contentAlignment = Alignment.Center | ||
) { | ||
FirebaseAuthUI( | ||
providers = providers, | ||
onSignInResult = onSignInResult, | ||
theme = R.style.AppTheme, | ||
logo = R.drawable.firebase_auth_120dp, | ||
tosUrl = "https://www.google.com/policies/terms/", | ||
privacyPolicyUrl = "https://www.google.com/policies/privacy/", | ||
enableCredentials = true, | ||
enableAnonymousUpgrade = false | ||
) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.firebase.uidemo.ui.theme | ||
|
||
import androidx.compose.ui.graphics.Color | ||
|
||
val Purple80 = Color(0xFFD0BCFF) | ||
val PurpleGrey80 = Color(0xFFCCC2DC) | ||
val Pink80 = Color(0xFFEFB8C8) | ||
|
||
val Purple40 = Color(0xFF6650a4) | ||
val PurpleGrey40 = Color(0xFF625b71) | ||
val Pink40 = Color(0xFF7D5260) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.firebase.uidemo.ui.theme | ||
|
||
import android.app.Activity | ||
import android.os.Build | ||
import androidx.compose.foundation.isSystemInDarkTheme | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.darkColorScheme | ||
import androidx.compose.material3.dynamicDarkColorScheme | ||
import androidx.compose.material3.dynamicLightColorScheme | ||
import androidx.compose.material3.lightColorScheme | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.SideEffect | ||
import androidx.compose.ui.graphics.toArgb | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.platform.LocalView | ||
import androidx.core.view.WindowCompat | ||
|
||
private val DarkColorScheme = darkColorScheme( | ||
primary = Purple80, | ||
secondary = PurpleGrey80, | ||
tertiary = Pink80 | ||
) | ||
|
||
private val LightColorScheme = lightColorScheme( | ||
primary = Purple40, | ||
secondary = PurpleGrey40, | ||
tertiary = Pink40 | ||
) | ||
|
||
@Composable | ||
fun FirebaseUIDemoTheme( | ||
darkTheme: Boolean = isSystemInDarkTheme(), | ||
dynamicColor: Boolean = true, | ||
content: @Composable () -> Unit | ||
) { | ||
val colorScheme = when { | ||
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { | ||
val context = LocalContext.current | ||
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) | ||
} | ||
darkTheme -> DarkColorScheme | ||
else -> LightColorScheme | ||
} | ||
val view = LocalView.current | ||
if (!view.isInEditMode) { | ||
SideEffect { | ||
val window = (view.context as Activity).window | ||
window.statusBarColor = colorScheme.primary.toArgb() | ||
WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme | ||
} | ||
} | ||
|
||
MaterialTheme( | ||
colorScheme = colorScheme, | ||
typography = Typography, | ||
content = content | ||
) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.firebase.uidemo.ui.theme | ||
|
||
import androidx.compose.material3.Typography | ||
import androidx.compose.ui.text.TextStyle | ||
import androidx.compose.ui.text.font.FontFamily | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.unit.sp | ||
|
||
val Typography = Typography( | ||
bodyLarge = TextStyle( | ||
fontFamily = FontFamily.Default, | ||
fontWeight = FontWeight.Normal, | ||
fontSize = 16.sp, | ||
lineHeight = 24.sp, | ||
letterSpacing = 0.5.sp | ||
), | ||
titleLarge = TextStyle( | ||
fontFamily = FontFamily.Default, | ||
fontWeight = FontWeight.Normal, | ||
fontSize = 22.sp, | ||
lineHeight = 28.sp, | ||
letterSpacing = 0.sp | ||
), | ||
labelSmall = TextStyle( | ||
fontFamily = FontFamily.Default, | ||
fontWeight = FontWeight.Medium, | ||
fontSize = 11.sp, | ||
lineHeight = 16.sp, | ||
letterSpacing = 0.5.sp | ||
) | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.