Skip to content

[AND-243] Save attachments on attachment picker dismiss #5554

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

Merged
merged 7 commits into from
Jan 23, 2025
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
### ⬆️ Improved

### ✅ Added
- Add `AttachmentsPickerDialogStyle::saveAttachmentsOnDismiss` flag for configuring whether the selected attachments should be saved when the dialog is dismissed. [#5554](https://github.com/GetStream/stream-chat-android/pull/5554)

### ⚠️ Changed

Expand All @@ -80,6 +81,7 @@
- Create snapshot tests for channels stateless components. [#5570](https://github.com/GetStream/stream-chat-android/pull/5570)

### ✅ Added
- Add `AttachmentsPickerTheme::saveAttachmentsOnDismiss` flag for configuring whether the selected attachments should be saved when the dialog is dismissed. [#5554](https://github.com/GetStream/stream-chat-android/pull/5554)

### ⚠️ Changed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2039,16 +2039,18 @@ public final class io/getstream/chat/android/compose/ui/pinned/PinnedMessageList
public final class io/getstream/chat/android/compose/ui/theme/AttachmentPickerTheme {
public static final field $stable I
public static final field Companion Lio/getstream/chat/android/compose/ui/theme/AttachmentPickerTheme$Companion;
public synthetic fun <init> (JJJLkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (JJJZLkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1-0d7_KjU ()J
public final fun component2-0d7_KjU ()J
public final fun component3-0d7_KjU ()J
public final fun copy-ysEtTa8 (JJJ)Lio/getstream/chat/android/compose/ui/theme/AttachmentPickerTheme;
public static synthetic fun copy-ysEtTa8$default (Lio/getstream/chat/android/compose/ui/theme/AttachmentPickerTheme;JJJILjava/lang/Object;)Lio/getstream/chat/android/compose/ui/theme/AttachmentPickerTheme;
public final fun component4 ()Z
public final fun copy-qwTeutE (JJJZ)Lio/getstream/chat/android/compose/ui/theme/AttachmentPickerTheme;
public static synthetic fun copy-qwTeutE$default (Lio/getstream/chat/android/compose/ui/theme/AttachmentPickerTheme;JJJZILjava/lang/Object;)Lio/getstream/chat/android/compose/ui/theme/AttachmentPickerTheme;
public fun equals (Ljava/lang/Object;)Z
public final fun getBackgroundOverlay-0d7_KjU ()J
public final fun getBackgroundPrimary-0d7_KjU ()J
public final fun getBackgroundSecondary-0d7_KjU ()J
public final fun getSaveAttachmentsOnDismiss ()Z
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.getstream.chat.android.compose.ui.messages.attachments

import androidx.activity.compose.BackHandler
import androidx.compose.animation.AnimatedContent
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
Expand Down Expand Up @@ -85,6 +86,14 @@ public fun AttachmentsPicker(
tabFactories: List<AttachmentsPickerTabFactory> = ChatTheme.attachmentsPickerTabFactories,
shape: Shape = ChatTheme.shapes.bottomSheet,
) {
val saveAttachmentsOnDismiss = ChatTheme.attachmentPickerTheme.saveAttachmentsOnDismiss
val dismissAction = {
if (saveAttachmentsOnDismiss) {
onAttachmentsSelected(attachmentsPickerViewModel.getSelectedAttachments())
}
onDismiss()
}
BackHandler(onBack = dismissAction)
val defaultTabIndex = tabFactories
.indexOfFirst { it.isPickerTabEnabled(attachmentsPickerViewModel.channel) }
.takeIf { it >= 0 }
Expand All @@ -98,7 +107,7 @@ public fun AttachmentsPicker(
.safeDrawingPadding()
.fillMaxSize()
.clickable(
onClick = onDismiss,
onClick = dismissAction,
indication = null,
interactionSource = remember { MutableInteractionSource() },
),
Expand Down Expand Up @@ -150,7 +159,7 @@ public fun AttachmentsPicker(
?.PickerTabContent(
onAttachmentPickerAction = { pickerAction ->
when (pickerAction) {
AttachmentPickerBack -> onDismiss.invoke()
AttachmentPickerBack -> dismissAction()
is AttachmentPickerPollCreation -> onAttachmentPickerAction.invoke(pickerAction)
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ import androidx.compose.ui.graphics.Color
* @param backgroundOverlay The overlay background color.
* @param backgroundSecondary The secondary background color.
* @param backgroundPrimary The primary background color.
* @param saveAttachmentsOnDismiss If the selected attachments should be saved when the picker is dismissed.
*/
@Immutable
public data class AttachmentPickerTheme(
val backgroundOverlay: Color,
val backgroundSecondary: Color,
val backgroundPrimary: Color,
val saveAttachmentsOnDismiss: Boolean,
) {

public companion object {
Expand All @@ -53,6 +55,7 @@ public data class AttachmentPickerTheme(
backgroundOverlay = colors.overlay,
backgroundSecondary = colors.inputBackground,
backgroundPrimary = colors.barsBackground,
saveAttachmentsOnDismiss = false,
)
}
}
Expand Down
Loading
Loading