-
Notifications
You must be signed in to change notification settings - Fork 287
[AND-464] Provide custom ImageLoader
to MediaGalleryPreviewActivity
.
#5736
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
base: develop
Are you sure you want to change the base?
Conversation
SDK Size Comparison 📏
|
# Conflicts: # stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/attachments/content/MediaAttachmentContent.kt
# Conflicts: # stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/attachments/content/MediaAttachmentContent.kt # stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/attachments/preview/MediaGalleryPreviewActivity.kt
|
val imageLoader = LocalStreamImageLoader.current | ||
LaunchedEffect(imageLoader) { | ||
MediaGalleryInjector.install(imageLoader) | ||
} | ||
|
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.
I'm just thinking out loud... this installation happens on every content item composition. Shouldn't it be moved higher in the chain instead? 🤔
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.
My idea was keep it close to where the MediaGalleryPreviewContract
is instantiated, so that the whole MediaGallery
setup is done in the same place. We can of course move it higher, but I was worried that we might lose context on what is done where. Where do you think it would be more appropriate to do this?
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.
Considering this composable might be called many times when it's a multiple attachment, maybe installing it in MediaAttachmentContent
WDYT?
Given you have touched more in this area than me, feel free to keep it this way or change it if you think it makes more sense.
* limitations under the License. | ||
*/ | ||
|
||
package io.getstream.chat.android.compose.ui.attachments.preview.internal |
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.
I'm my opinion, no need to have it inside a internal package.
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.
This is a pattern that is used in some places - placing the internal
-only classes/methods in a separate internal
package. I can of course move it, but maybe we should agree on a global level how to proceed with the structure of such internal
methods/classes.
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.
Sure. Let's bring this topic to Slack 👍🏻
* | ||
* @param imageLoader The [ImageLoader] instance to set. | ||
*/ | ||
internal fun install(imageLoader: ImageLoader) { |
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.
The object is already internal. I believe internal
is not needed here
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.
Will update it!
🎯 Goal
Currently it is not possible to use custom
ImageLoader
s inside theMediaGalleryPreviewActivity
because it is an Activity that is launched from the SDK, and it is not possible to pass customimageLoaderFactory
(or other customization) via theChatTheme
.With this PR, we introduce an internal way of passing the
ImageLoader
from theMediaAttachmentContent
to theMediaGalleryPreviewActivity
. This ensures that if a customStreamCoilImageLoaderFactory
is passed to theChatTheme
wrapping theMediaAttachmentContent
, the same one is used in theMediaGalleryPreviewActivity
as well.🛠 Implementation details
Introduce a
MediaGalleryInjector
- a global holder for theImageLoader
. It is populated from theMediaAttachmentContent
(it can be done from anywhere, but I placed it there as it is directly linked to theMediaGalleryPreviewActivity
). It is then read from theMediaGalleryPreviewActivity
, and is bound to the localLocalStreamImageLoader
.🧪 Testing
DefaultStreamCoilImageLoaderFactory
, and defines aCustomCoilImageLoaderFactory
- which has a different logging mechanism. It then provides the new factory in theMessagesActivity
sChatTheme
.StreamImageLoader
: The logs on the channel list should originate from the default imageLoader, while the logs from the messages/mediaGallery should originate from the custom imageLoader.Patch