Skip to content

Dismissing GalleryVC when using RTL layout #3745

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 6 commits into from
Jul 28, 2025
Merged

Conversation

laevandus
Copy link
Contributor

@laevandus laevandus commented Jul 24, 2025

🔗 Issue Links

Resolves: https://linear.app/stream/issue/IOS-996

🎯 Goal

Dismissing GalleryVC when using RTL layout did not work

📝 Summary

  • Fix page index issue causing the problem in RTL
  • Fix flickering when opening the view

🛠 Implementation

Dismissing did not work because the transition coordinator failed to get the source view and then it did nothing and left the app in inconsistent state.

🎨 Showcase

Before After
img img

🧪 Manual Testing Notes

Open scheme settings for run, and set app language to right to left pseudolanguage

  1. Send multiple images
  2. Open the gallery view, try swiping and closing the gallery

☑️ Contributor Checklist

  • I have signed the Stream CLA (required)
  • This change should be manually QAed
  • Changelog is updated with client-facing changes
  • Changelog is updated with new localization keys
  • New code is covered by unit tests
  • Documentation has been updated in the docs-content repo

Summary by CodeRabbit

Summary by CodeRabbit

  • Bug Fixes

    • Improved gallery swiping and dismissal behavior for right-to-left (RTL) layouts, ensuring correct page tracking and navigation.
    • Fixed gallery scrolling to the current page on view appearance for smoother user experience in all layouts.
  • Documentation

    • Updated release notes to include details about the RTL gallery fix.

@laevandus laevandus requested a review from a team as a code owner July 24, 2025 12:31
@laevandus laevandus added 🐞 Bug An issue or PR related to a bug 🎨 SDK: StreamChatUI Tasks related to the StreamChatUI SDK 🤞 Ready For QA A PR that is Ready for QA labels Jul 24, 2025
Copy link

coderabbitai bot commented Jul 24, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The changes refactor how the current page is tracked and scrolled to in the GalleryVC class, moving scroll logic from viewDidLoad to viewDidAppear, and updating page calculation to properly support right-to-left (RTL) layouts. The updateCurrentPage method now adjusts the page index based on interface layout direction.

Changes

File(s) Change Summary
GalleryVC refactor and RTL support
Sources/StreamChatUI/Gallery/GalleryVC.swift
Refactored page scroll logic: moved scroll to viewDidAppear, updated updateCurrentPage for RTL, added layout direction handling, and revised method signatures.
Changelog update
CHANGELOG.md
Added "Fixed" section documenting the RTL dismiss fix for GalleryVC referencing PR #3745.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant GalleryVC
    participant CollectionView

    User->>GalleryVC: View appears
    GalleryVC->>CollectionView: Scroll to current page (no animation)
    User->>GalleryVC: Scrolls collection view
    GalleryVC->>GalleryVC: updateCurrentPage()
    alt Layout is RTL
        GalleryVC->>GalleryVC: Calculate reversed page index
    else Layout is LTR
        GalleryVC->>GalleryVC: Calculate normal page index
    end
    GalleryVC->>GalleryVC: Set content.currentPage
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Assessment against linked issues

Objective Addressed Explanation
Fix GalleryVC dismiss does not work in RTL due to incorrect content.currentPage calculation (IOS-996)
Review and fix content.currentPage logic to handle RTL layout properly (IOS-996)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes detected.

Possibly related PRs

Poem

A hop to the left, a hop to the right,
Gallery pages now scroll just right.
RTL or LTR, the logic is clear,
No more confusion—dismissals appear!
With every swipe, the bugs take flight,
The gallery’s fixed—oh, what a delight!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2c850ac and fdb64aa.

⛔ Files ignored due to path filters (3)
  • Tests/StreamChatUITests/SnapshotTests/Gallery/__Snapshots__/GalleryVC_Tests/test_appearanceCustomization_usingSubclassing.rightToLeftLayout-default.png is excluded by !**/*.png
  • Tests/StreamChatUITests/SnapshotTests/Gallery/__Snapshots__/GalleryVC_Tests/test_appearanceCustomization_usingUIConfig.rightToLeftLayout-default.png is excluded by !**/*.png
  • Tests/StreamChatUITests/SnapshotTests/Gallery/__Snapshots__/GalleryVC_Tests/test_defaultAppearance.rightToLeftLayout-default.png is excluded by !**/*.png
📒 Files selected for processing (1)
  • CHANGELOG.md (1 hunks)
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/rtl-gallery

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@laevandus laevandus changed the title Fix closing GalleryVC when using RTL layout Dismissing GalleryVC when using RTL layout Jul 24, 2025
Copy link

Public Interface

 open class GalleryVC: _ViewController, UIGestureRecognizerDelegate, AppearanceProvider, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout, ComponentsProvider  
-   override open func viewWillDisappear(_ animated: Bool)
+   override open func viewDidAppear(_ animated: Bool)
-   override open func updateContent()
+   override open func viewWillDisappear(_ animated: Bool)
-   @objc open func handlePan(with gestureRecognizer: UIPanGestureRecognizer)
+   override open func updateContent()
-   @objc open func closeButtonTapped()
+   @objc open func handlePan(with gestureRecognizer: UIPanGestureRecognizer)
-   @objc open func shareButtonTapped()
+   @objc open func closeButtonTapped()
-   open func updateCurrentPage()
+   @objc open func shareButtonTapped()
-   open func collectionView(_ collectionView: UICollectionView,numberOfItemsInSection section: Int)-> Int
+   open func updateCurrentPage()
-   open func collectionView(_ collectionView: UICollectionView,cellForItemAt indexPath: IndexPath)-> UICollectionViewCell
+   open func collectionView(_ collectionView: UICollectionView,numberOfItemsInSection section: Int)-> Int
-   open func collectionView(_ collectionView: UICollectionView,layout collectionViewLayout: UICollectionViewLayout,sizeForItemAt indexPath: IndexPath)-> CGSize
+   open func collectionView(_ collectionView: UICollectionView,cellForItemAt indexPath: IndexPath)-> UICollectionViewCell
-   open func collectionView(_ collectionView: UICollectionView,targetContentOffsetForProposedContentOffset proposedContentOffset: CGPoint)-> CGPoint
+   open func collectionView(_ collectionView: UICollectionView,layout collectionViewLayout: UICollectionViewLayout,sizeForItemAt indexPath: IndexPath)-> CGSize
-   open func scrollViewDidEndDecelerating(_ scrollView: UIScrollView)
+   open func collectionView(_ collectionView: UICollectionView,targetContentOffsetForProposedContentOffset proposedContentOffset: CGPoint)-> CGPoint
-   open func scrollViewDidScroll(_ scrollView: UIScrollView)
+   open func scrollViewDidEndDecelerating(_ scrollView: UIScrollView)
-   override open func viewWillTransition(to size: CGSize,with coordinator: UIViewControllerTransitionCoordinator)
+   open func scrollViewDidScroll(_ scrollView: UIScrollView)
-   open func shareItem(at indexPath: IndexPath)-> Any?
+   override open func viewWillTransition(to size: CGSize,with coordinator: UIViewControllerTransitionCoordinator)
-   open func cellReuseIdentifierForItem(at indexPath: IndexPath)-> String?
+   open func shareItem(at indexPath: IndexPath)-> Any?
-   open func handleSingleTapOnCell(at indexPath: IndexPath)
+   open func cellReuseIdentifierForItem(at indexPath: IndexPath)-> String?
-   
+   open func handleSingleTapOnCell(at indexPath: IndexPath)
- 
+   
-   public struct Content  
+ 
-   
+   public struct Content  
-     public var message: ChatMessage
+   
-     public var currentPage: Int
+     public var message: ChatMessage
-     
+     public var currentPage: Int
-   
+     
-     public init(message: ChatMessage,currentPage: Int = 0)
+   
+     public init(message: ChatMessage,currentPage: Int = 0)

Copy link

1 Warning
⚠️ The changes should be manually QAed before the Pull Request will be merged

Generated by 🚫 Danger

@Stream-SDK-Bot
Copy link
Collaborator

Stream-SDK-Bot commented Jul 24, 2025

SDK Size

title develop branch diff status
StreamChat 7.92 MB 7.92 MB 0 KB 🟢
StreamChatUI 4.84 MB 4.84 MB 0 KB 🟢

Copy link

Public Interface

 open class GalleryVC: _ViewController, UIGestureRecognizerDelegate, AppearanceProvider, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout, ComponentsProvider  
-   override open func viewWillDisappear(_ animated: Bool)
+   override open func viewDidAppear(_ animated: Bool)
-   override open func updateContent()
+   override open func viewWillDisappear(_ animated: Bool)
-   @objc open func handlePan(with gestureRecognizer: UIPanGestureRecognizer)
+   override open func updateContent()
-   @objc open func closeButtonTapped()
+   @objc open func handlePan(with gestureRecognizer: UIPanGestureRecognizer)
-   @objc open func shareButtonTapped()
+   @objc open func closeButtonTapped()
-   open func updateCurrentPage()
+   @objc open func shareButtonTapped()
-   open func collectionView(_ collectionView: UICollectionView,numberOfItemsInSection section: Int)-> Int
+   open func updateCurrentPage()
-   open func collectionView(_ collectionView: UICollectionView,cellForItemAt indexPath: IndexPath)-> UICollectionViewCell
+   open func collectionView(_ collectionView: UICollectionView,numberOfItemsInSection section: Int)-> Int
-   open func collectionView(_ collectionView: UICollectionView,layout collectionViewLayout: UICollectionViewLayout,sizeForItemAt indexPath: IndexPath)-> CGSize
+   open func collectionView(_ collectionView: UICollectionView,cellForItemAt indexPath: IndexPath)-> UICollectionViewCell
-   open func collectionView(_ collectionView: UICollectionView,targetContentOffsetForProposedContentOffset proposedContentOffset: CGPoint)-> CGPoint
+   open func collectionView(_ collectionView: UICollectionView,layout collectionViewLayout: UICollectionViewLayout,sizeForItemAt indexPath: IndexPath)-> CGSize
-   open func scrollViewDidEndDecelerating(_ scrollView: UIScrollView)
+   open func collectionView(_ collectionView: UICollectionView,targetContentOffsetForProposedContentOffset proposedContentOffset: CGPoint)-> CGPoint
-   open func scrollViewDidScroll(_ scrollView: UIScrollView)
+   open func scrollViewDidEndDecelerating(_ scrollView: UIScrollView)
-   override open func viewWillTransition(to size: CGSize,with coordinator: UIViewControllerTransitionCoordinator)
+   open func scrollViewDidScroll(_ scrollView: UIScrollView)
-   open func shareItem(at indexPath: IndexPath)-> Any?
+   override open func viewWillTransition(to size: CGSize,with coordinator: UIViewControllerTransitionCoordinator)
-   open func cellReuseIdentifierForItem(at indexPath: IndexPath)-> String?
+   open func shareItem(at indexPath: IndexPath)-> Any?
-   open func handleSingleTapOnCell(at indexPath: IndexPath)
+   open func cellReuseIdentifierForItem(at indexPath: IndexPath)-> String?
-   
+   open func handleSingleTapOnCell(at indexPath: IndexPath)
- 
+   
-   public struct Content  
+ 
-   
+   public struct Content  
-     public var message: ChatMessage
+   
-     public var currentPage: Int
+     public var message: ChatMessage
-     
+     public var currentPage: Int
-   
+     
-     public init(message: ChatMessage,currentPage: Int = 0)
+   
+     public init(message: ChatMessage,currentPage: Int = 0)

Copy link

Public Interface

 open class GalleryVC: _ViewController, UIGestureRecognizerDelegate, AppearanceProvider, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout, ComponentsProvider  
-   override open func viewWillDisappear(_ animated: Bool)
+   override open func viewDidAppear(_ animated: Bool)
-   override open func updateContent()
+   override open func viewWillDisappear(_ animated: Bool)
-   @objc open func handlePan(with gestureRecognizer: UIPanGestureRecognizer)
+   override open func updateContent()
-   @objc open func closeButtonTapped()
+   @objc open func handlePan(with gestureRecognizer: UIPanGestureRecognizer)
-   @objc open func shareButtonTapped()
+   @objc open func closeButtonTapped()
-   open func updateCurrentPage()
+   @objc open func shareButtonTapped()
-   open func collectionView(_ collectionView: UICollectionView,numberOfItemsInSection section: Int)-> Int
+   open func updateCurrentPage()
-   open func collectionView(_ collectionView: UICollectionView,cellForItemAt indexPath: IndexPath)-> UICollectionViewCell
+   open func collectionView(_ collectionView: UICollectionView,numberOfItemsInSection section: Int)-> Int
-   open func collectionView(_ collectionView: UICollectionView,layout collectionViewLayout: UICollectionViewLayout,sizeForItemAt indexPath: IndexPath)-> CGSize
+   open func collectionView(_ collectionView: UICollectionView,cellForItemAt indexPath: IndexPath)-> UICollectionViewCell
-   open func collectionView(_ collectionView: UICollectionView,targetContentOffsetForProposedContentOffset proposedContentOffset: CGPoint)-> CGPoint
+   open func collectionView(_ collectionView: UICollectionView,layout collectionViewLayout: UICollectionViewLayout,sizeForItemAt indexPath: IndexPath)-> CGSize
-   open func scrollViewDidEndDecelerating(_ scrollView: UIScrollView)
+   open func collectionView(_ collectionView: UICollectionView,targetContentOffsetForProposedContentOffset proposedContentOffset: CGPoint)-> CGPoint
-   open func scrollViewDidScroll(_ scrollView: UIScrollView)
+   open func scrollViewDidEndDecelerating(_ scrollView: UIScrollView)
-   override open func viewWillTransition(to size: CGSize,with coordinator: UIViewControllerTransitionCoordinator)
+   open func scrollViewDidScroll(_ scrollView: UIScrollView)
-   open func shareItem(at indexPath: IndexPath)-> Any?
+   override open func viewWillTransition(to size: CGSize,with coordinator: UIViewControllerTransitionCoordinator)
-   open func cellReuseIdentifierForItem(at indexPath: IndexPath)-> String?
+   open func shareItem(at indexPath: IndexPath)-> Any?
-   open func handleSingleTapOnCell(at indexPath: IndexPath)
+   open func cellReuseIdentifierForItem(at indexPath: IndexPath)-> String?
-   
+   open func handleSingleTapOnCell(at indexPath: IndexPath)
- 
+   
-   public struct Content  
+ 
-   
+   public struct Content  
-     public var message: ChatMessage
+   
-     public var currentPage: Int
+     public var message: ChatMessage
-     
+     public var currentPage: Int
-   
+     
-     public init(message: ChatMessage,currentPage: Int = 0)
+   
+     public init(message: ChatMessage,currentPage: Int = 0)

@laevandus laevandus merged commit 09bc15b into develop Jul 28, 2025
4 of 6 checks passed
@laevandus laevandus deleted the fix/rtl-gallery branch July 28, 2025 05:40
Copy link

Public Interface

 open class SlideToCancelView: _View, ThemeProvider  
-   override open func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?)
+   override open func updateContent()
-   override open func updateContent()
+   
-   
+ 
- 
+   public struct Content: Equatable  
-   public struct Content: Equatable  
+   
-   
+     public var alpha: CGFloat
-     public var alpha: CGFloat
+     
-     
+   
-   
+     public init(alpha: CGFloat)
-     public init(alpha: CGFloat)

Copy link

@Stream-SDK-Bot Stream-SDK-Bot mentioned this pull request Jul 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 Bug An issue or PR related to a bug 🤞 Ready For QA A PR that is Ready for QA 🎨 SDK: StreamChatUI Tasks related to the StreamChatUI SDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants