-
Notifications
You must be signed in to change notification settings - Fork 90
Adjust component Image #105
Comments
@uziasferreirazup @victormr
|
@pedropnaves I agree with this. |
@pedropnaves @uziasferreirazup @victormr Example creating an image in Swift (I don't know how exactly it would be in Kotlin): let localImage = Image(type: .local("imageName"))
let remoteImage = Image(type: .remote("https://www.google.com")) |
But that would essentially mean that separating local and network images isn't an issue, as you would have two classes for images.
This example is problematic for serializing and deserializing, since both would become something like |
What is the purpose of the data class Image(
val url: String,
val typeURLImage: TypeURLImage,
val contentMode: ImageContentMode? = null
) : Widget() |
I talked about "sealed classes" because that's usually what is referred in Kotlin to be semantically equal to "enum with associated values" in Swift, but maybe there is a better solution. The solution that I was talking about is to encapsulate that 3 parameters (name, url, and type) into 1 parameter with 2 possible values (local or remote with a String parameter value).
Yeah, the json itself would still need 2 different properties (e.g: name and url), but the Kotlin API would be better: not allowing users to provide both properties at once.
The only problem with this is that when it's a local image, the value of |
Suppose we want to show the Beagle logo and the application logo in a view. The apllication logo is stored locally and the Beagle logo is remote, in the bff.
We can't suppress "typeURLImage". If we do so, we have no way of knowing if the url is relative to the bff or to the local application (web). Making it impossible to represent both of the use-cases above. We can't suppress "name". If we do so, we can't specify an image value to the mobile applications and another one to the web application. It would make it impossible to represent the second use case. If we really want to use only "url" and ditch "name", we could make the identifier of an image (mobile) equal to the url of the same image in the web application. But, I really don't think we should relate an id in iOS or Android to a random URL of the web app. |
@theffc @Tiagoperes |
@theffc |
There's still the second observation of my commentary ("we can't suppress name"). As I said, by unifying the fields "name" and "url", we can't say that the local image is "logo" for mobile applications and "/assets/images/logo.png" for web applications. Can we do it? Yes, but with a clear loss: the url of the web application would have to be used as the identifiers of the images in the mobile apps. Instead of "logo", in both iOS and Android, this image would be mapped with the key "/assets/images/logo.png". Which I really don't think is a good idea. We could also process this string "/assets/images/logo.png", using the complete value in web applications and extracting only the filename to use as the image id in the mobile apps. But I think it can be a bit obscure to the developer. |
@Tiagoperes data class Image(val path: ImagePath, val mode: ImageContentMode? = null)
sealed class ImagePath(val url: String)
class LocalImagePath(webUrl: String, val mobileId: String): ImagePath(webUrl)
class RemoteImagePath(remoteUrl: String): ImagePath(remoteUrl) It would be used as follows: val localImage = Image(LocalImagePath("/assets/images/logo.png", "logo"))
val remoteImage = Image(RemoteImagePath("/images/beagle-logo.png")) I find it better than the initial proposed class because name would be useless for remote source images. However, I question if it is not too similar to a semantically clearer version of our current classes, as such: sealed class Image(val url: String, val mode: ImageContentMode?)
class LocalImage(
webUrl: String,
val mobileId: String,
mode: ImageContentMode? = null
): Image(webUrl, mode)
class RemoteImage(
remoteUrl: String,
mode: ImageContentMode? = null
): Image(remoteUrl, mode) Which is used like: val localImage = LocalImage("/assets/images/logo.png", "logo")
val remoteImage = RemoteImage("/images/beagle-logo.png") |
@LG95 just to be sure that I understood, this code you are proposing still have a complexity overhead when serializing and deserializing, right? I preferred the first one. And maybe we could even get more scoped types, like: data class Image(val path: ImagePath, val mode: ImageContentMode? = null)
sealed class ImagePath(val url: String) {
class Local(webUrl: String, val mobileId: String): ImagePath(webUrl)
class Remote(remoteUrl: String): ImagePath(remoteUrl)
}
val local = Image(ImagePath.Local("/assets/images/logo.png", "logo"))
val remote = Image(ImagePath.Remote("/images/beagle-logo.png")) |
@theffc only the first option requires custom serialization and deserialization. The second is handled by the beagle type serialization mechanism. I prefer the scoped version of option 1 as you proposed and they are legal Kotlin. |
I'm fine with both approaches, we can express all we need in both of them. |
A question considering the mode "Network": If the mode is Network, it means that, if the url is relative, it is relative to the backend URL, right? Suppose the URL to fetch the json with an image is at "http://www.zup.com/beagle/movies". If the image returned in this json is of type Network and has
I believe I have this question because we didn't mess too much with the navigation in beagle-web. I'd appreciate if someone could explain to me how beagle-ios and beagle-android deal with these Urls. |
@Tiagoperes I believe we should follow our URL convention and according to it, the final URL would be http://www.zup.com/beagle/movies/images/poster36.png. |
@LG95 how could I express that the URL is actually http://www.zup.com/beagle/images/poster36.png? we don't accept |
@Tiagoperes unfortunately, we only support a very simple relative path. Therefore, http://www.zup.com/beagle/images/poster36.png will need to be expressed as absolute. Alternatively, maybe your base URL should be http://www.zup.com/beagle/. We documented the complete URL convention in https://docs.usebeagle.io/conventions/urls. |
This problem with the URL is deeper and should be discussed in greater details elsewhere. If any changes to the image component emerge from this discussion, I'll post it here. |
I have an observation, in this usage: Even if i don't have a web or a mobile app i still have to pass both parameters for no reason. To minimize this problem i have a proposal to instead of the "Local" enum is associated with 2 strings we create a struct to associate with this type. This struct will have multiple initializers so we can ensure that we have the properties we need. I propose 2 structs:
|
@theffc @LG95 @Tiagoperes Any opinion on this? |
@victormr Do you propose these classes as alternatives to the |
Is a addition, instead of the
Instead of: Reducing the necessity of sending both parameter every time. |
@victormr Sounds reasonable to me. |
Describe the problem
Actual has two components Image and NetworkImage and they do the same think load an image.
Expected behavior
Remove component NetworkImage and add support to load image from network in component Image
Actual Component
Expected Component
The text was updated successfully, but these errors were encountered: