-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Antoine Robiez <[email protected]>
- Loading branch information
Showing
4 changed files
with
92 additions
and
67 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
shared/ui/src/androidMain/kotlin/com/androidmakers/ui/common/SigninButton.android.kt
This file contains 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,74 @@ | ||
package com.androidmakers.ui.common | ||
|
||
import androidx.compose.foundation.Image | ||
import androidx.compose.foundation.shape.CircleShape | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.rounded.AccountCircle | ||
import androidx.compose.material3.DropdownMenu | ||
import androidx.compose.material3.DropdownMenuItem | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.IconButton | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.clip | ||
import com.seiko.imageloader.rememberImagePainter | ||
import dev.icerock.moko.resources.compose.stringResource | ||
import fr.androidmakers.domain.model.User | ||
import fr.paug.androidmakers.ui.MR | ||
|
||
@Composable | ||
actual fun SigninButton( | ||
user: User?, | ||
callbacks: SigninCallbacks, | ||
) { | ||
val expandedState = remember { mutableStateOf(false) } | ||
|
||
IconButton( | ||
onClick = { | ||
expandedState.value = true | ||
} | ||
) { | ||
if (user == null) { | ||
Icon( | ||
imageVector = Icons.Rounded.AccountCircle, | ||
contentDescription = stringResource(MR.strings.signin) | ||
) | ||
} else { | ||
Image( | ||
modifier = Modifier.clip(CircleShape), | ||
painter = rememberImagePainter(user.photoUrl ?: ""), | ||
contentDescription = stringResource(MR.strings.signout) | ||
) | ||
} | ||
} | ||
|
||
DropdownMenu( | ||
expanded = expandedState.value, | ||
onDismissRequest = { expandedState.value = false } | ||
) { | ||
if (user == null) { | ||
DropdownMenuItem( | ||
text = { | ||
Text(stringResource(MR.strings.signin)) | ||
}, | ||
onClick = { | ||
expandedState.value = false | ||
callbacks.signin() | ||
} | ||
) | ||
} else { | ||
DropdownMenuItem( | ||
text = { | ||
Text(stringResource(MR.strings.signout)) | ||
}, | ||
onClick = { | ||
expandedState.value = false | ||
callbacks.signout() | ||
} | ||
) | ||
} | ||
} | ||
} |
68 changes: 2 additions & 66 deletions
68
shared/ui/src/commonMain/kotlin/com/androidmakers/ui/common/SigninButton.kt
This file contains 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,79 +1,15 @@ | ||
package com.androidmakers.ui.common | ||
|
||
import androidx.compose.foundation.Image | ||
import androidx.compose.foundation.shape.CircleShape | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.rounded.AccountCircle | ||
import androidx.compose.material3.DropdownMenu | ||
import androidx.compose.material3.DropdownMenuItem | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.IconButton | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.clip | ||
import com.seiko.imageloader.rememberImagePainter | ||
import dev.icerock.moko.resources.compose.stringResource | ||
import fr.androidmakers.domain.model.User | ||
import fr.paug.androidmakers.ui.MR | ||
|
||
class SigninCallbacks( | ||
val signin: () -> Unit, | ||
val signout: () -> Unit, | ||
) | ||
|
||
@Composable | ||
fun SigninButton( | ||
expect fun SigninButton( | ||
user: User?, | ||
callbacks: SigninCallbacks, | ||
) { | ||
val expandedState = remember { mutableStateOf(false) } | ||
|
||
IconButton( | ||
onClick = { | ||
expandedState.value = true | ||
} | ||
) { | ||
if (user == null) { | ||
Icon( | ||
imageVector = Icons.Rounded.AccountCircle, | ||
contentDescription = stringResource(MR.strings.signin) | ||
) | ||
} else { | ||
Image( | ||
modifier = Modifier.clip(CircleShape), | ||
painter = rememberImagePainter(user.photoUrl ?: ""), | ||
contentDescription = stringResource(MR.strings.signout) | ||
) | ||
} | ||
} | ||
|
||
DropdownMenu( | ||
expanded = expandedState.value, | ||
onDismissRequest = { expandedState.value = false } | ||
) { | ||
if (user == null) { | ||
DropdownMenuItem( | ||
text = { | ||
Text(stringResource(MR.strings.signin)) | ||
}, | ||
onClick = { | ||
expandedState.value = false | ||
callbacks.signin() | ||
} | ||
) | ||
} else { | ||
DropdownMenuItem( | ||
text = { | ||
Text(stringResource(MR.strings.signout)) | ||
}, | ||
onClick = { | ||
expandedState.value = false | ||
callbacks.signout() | ||
} | ||
) | ||
} | ||
} | ||
} | ||
) |
This file contains 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
11 changes: 11 additions & 0 deletions
11
shared/ui/src/iosMain/kotlin/com/androidmakers/ui/common/SigninButton.ios.kt
This file contains 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.androidmakers.ui.common | ||
|
||
import androidx.compose.runtime.Composable | ||
import fr.androidmakers.domain.model.User | ||
|
||
@Composable | ||
actual fun SigninButton( | ||
user: User?, | ||
callbacks: SigninCallbacks | ||
) { | ||
} |