Port the media layout algorithm from the Android app#992
Port the media layout algorithm from the Android app#992grishka wants to merge 10 commits intomastodon:developfrom
Conversation
|
I think you need to call |
|
Nope, it made no difference =/ |
| MediaLayoutResult.Tile(colSpan: 1, rowSpan: 1, startCol: 2, startRow: 1) | ||
| ]) | ||
| } else { | ||
| // One on the left, three smaller ones on the right |
There was a problem hiding this comment.
Does this mean 4 attachments will never be rendered as a 2x2 grid?
There was a problem hiding this comment.
Yes, it's always 1 bigger one and 3 smaller ones
MastodonSDK/Sources/MastodonUI/View/Container/MediaGridContainerView.swift
Outdated
Show resolved
Hide resolved
MastodonSDK/Sources/MastodonUI/View/Container/MediaGridContainerView.swift
Outdated
Show resolved
Hide resolved
MastodonSDK/Sources/MastodonUI/View/Container/MediaGridContainerView.swift
Outdated
Show resolved
Hide resolved
Co-authored-by: Jed Fox <git@jedfox.com>
|
Another interesting observation — if a post has a broken layout, but I then tap it to open separately, that screen has a correct layout. Might it be that images loading asynchronously affect the layout inside MediaView somehow? |
|
@grishka The behavior where the image extends beyond the bounds occurs because MediaView instances are reused in You can add |
|
Yeah, I figured that out. The problem was that, iirc, when there was a single attachment, |



As discussed, I tried to port the media layout algorithm from the Android app. Android sources: the layout algorithm itself and the custom ViewGroup that actually puts the views on the screen. This new layout algorithm works with up to 10 media attachments.
I'm not familiar with Swift and UIKit, and definitely not with ReactiveSwift that permeates the entire codebase of the app. I might have done something stupid.
This PR isn't quite ready for merging. There's something inside


MediaViewthat doesn't respect its frame and won't crop vertically, resulting in overlapping views:There's also a bug I don't know how to fix because I don't know where to hook into either the app or UIKit to re-run the layout with new
maxSizewhen the view size changes. Android would automatically measure and then lay out the view subtree when the dimensions of its parentViewGroupchange, but iOS apparently doesn't do that? To reproduce, open an attachment, rotate the device to landscape orientation, then close the attachment.