Skip to content
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

Adds Polls UI Components + Introducing View Container Builder #3435

Merged
merged 35 commits into from
Oct 1, 2024

Conversation

nuno-vieira
Copy link
Member

@nuno-vieira nuno-vieira commented Sep 26, 2024

🔗 Issue Links

Resolves https://stream-io.atlassian.net/browse/PBE-4287

🎯 Goal

Adds Poll UIKit components and introduces the new View Container Builder.

📝 Summary

This is the final PR that groups the following PRs:

  • Add PollAttachmentView + ViewContainerBuilder #3374
  • Add PollResultsVC #3381
  • Comments + Suggestions + Anonymous Polls + LLC Fixes #3398
  • Add Poll Creation Flow #3433

Additionally:

  • Adds PollAllOptionsListVC component
  • It fixes a bug where the poll.latestAnswers and poll.ownVotes were impacting each other, causing the "Add a comment" button to disappear when adding a regular vote. (There was an attempt to fix this here but it did not fix 100%)
  • Removes the layout {} and constraints {} from ViewContainerBuilder since adding constraints before the view hierarchy is not possible
  • Adds padding() helper to ViewContainerBuilder

Features Missing:
- The only thing missing, which will be out of scope for now, is the limit of 10 options for each Poll in the message list, plus the additional view to see all the votes.

🛠 Implementation

Below is the summary of all the components added.

PollAttachmentView

graph LR
    PollAttachmentView --> headerView
    headerView --> titleLabel & subtitleLabel
    PollAttachmentView --> PollAttachmentOptionListView
    PollAttachmentOptionListView --> PollAttachmentOptionListItemView
    PollAttachmentView --> footerView
    footerView --> ViewResultsButton & EndPollButton
Loading

PollResultsVC

graph LR
    PollResultsVC --> PollResultsTableHeaderView
    PollResultsVC --> PollResultsSectionHeaderView
    PollResultsVC --> PollResultsVoteItemCell
    PollResultsVoteItemCell --> PollResultsVoteItemView
    PollResultsVC --> PollResultsSectionFooterView
Loading

PollResultsVoteListVC

graph LR
    PollResultsVoteListVC --> PollResultsSectionHeaderView
    PollResultsVoteListVC--> PollResultsVoteItemCell
    PollResultsVoteItemCell --> PollResultsVoteItemView
Loading

PollCommentListVC

graph LR
    PollCommentListVC --> PollCommentListSectionHeaderView
    PollCommentListVC  --> PollCommentListItemCell
    PollCommentListItemCell --> PollCommentListItemView --> PollResultsVoteItemView
    PollCommentListVC  --> PollCommentListTableFooterView
Loading

PollCreationVC

graph LR
    PollCreationVC --> PollCreationSectionHeaderView
    PollCreationVC  --> PollCreationNameCell --> PollCreationTextFieldView
    PollCreationVC  --> PollCreationOptionCell --> PollCreationTextFieldView
    PollCreationVC  --> PollCreationFeatureCell --> PollCreationFeatureSwitchView
    PollCreationVC  --> PollCreationMultipleVotesFeatureCell --> PollCreationFeatureSwitchView
Loading

PollAllOptionsListVC

graph LR
    PollAllOptionsListVC -->PollAllOptionsListItemCell
Loading

🎨 Showcase

Quick demo of the main features:

Simulator.Screen.Recording.-.iPhone.15.Pro.17.4.-.2024-09-26.at.23.21.54.mov

🧪 Manual Testing Notes

Poll Creation View

Things to test:

  • When typing the poll's name or adding an option, pressing "next" should go to the next textfield
  • Sorting the options
  • When typing an option, it should create a new one next
  • Backspacing an empty option, should delete it
  • Duplicate Options is not allowed
  • Enabling / Disabling features
  • Error Validation: Creating a Poll with Errors should not be possible. The send button should be disabled in case there are errors.

Message Poll Attachment View

Things to test:

  • The poll's subtitle should say "Select One", "Select One or More" or "Select up to X" depending on the multiple votes configuration
  • Multiple votes should not be allowed in case only one vote per user is required
  • Suggesting an option should add a new option to the list
  • Adding a comment should update buttons to include "View Comments" and remove the "Add comment" button in case the poll is not anonymous
  • Ending a vote should close the Poll, and if there is only one winner, the bar should be green

Poll Comments

Things to test:

  • Updating a comment
  • Loading multiple comments

Poll Results

Things to test:

  • Loading multiple votes

Channel List Message Previews (When last message is a poll)

Things to test:

  • When the current user created a poll
  • When another user created a poll
  • When the current user voted a poll
  • When another user voted a poll

Quoting a Poll

Things to test:

  • When quoting a poll, the quoted message should show a Poll icon and the poll's name

☑️ 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
  • Comparison screenshots added for visual changes
  • Affected documentation updated (docusaurus, tutorial, CMS)

@nuno-vieira nuno-vieira added the ✅ Feature An issue or PR related to a feature label Sep 26, 2024
@nuno-vieira nuno-vieira requested a review from a team as a code owner September 26, 2024 17:57
@nuno-vieira nuno-vieira changed the title [Polls] Adds Polls UI Components + View Container Builder Introduction [Polls] Adds Polls UI Components + Introducing View Container Builder Sep 26, 2024
@Stream-SDK-Bot
Copy link
Collaborator

SDK Size

title develop branch diff status
StreamChat 6.85 MB 6.9 MB +51 KB 🟢
StreamChatUI 4.42 MB 4.89 MB +490 KB 🟢

@Stream-SDK-Bot
Copy link
Collaborator

SDK Performance

target metric benchmark branch performance status
MessageList Hitches total duration 10 ms 6.68 ms 33.2% 🔼 🟢
Duration 2.6 s 2.56 s 1.54% 🔼 🟢
Hitch time ratio 4 ms per s 2.61 ms per s 34.75% 🔼 🟢
Frame rate 75 fps 78.29 fps 4.39% 🔼 🟢
Number of hitches 1 0.8 20.0% 🔼 🟢
ChannelList Hitches total duration 12.5 ms 20.03 ms -60.24% 🔽 🔴
Duration 2.6 s 2.54 s 2.31% 🔼 🟢
Hitch time ratio 5 ms per s 7.9 ms per s -58.0% 🔽 🔴
Frame rate 72 fps 74.23 fps 3.1% 🔼 🟢
Number of hitches 1.2 1.6 -33.33% 🔽 🔴

Copy link

1 Warning
⚠️ Big PR

Generated by 🚫 Danger

@Stream-SDK-Bot
Copy link
Collaborator

Stream-SDK-Bot commented Sep 26, 2024

SDK Size

title develop branch diff status
StreamChat 6.85 MB 6.9 MB +51 KB 🟢
StreamChatUI 4.42 MB 4.95 MB +546 KB 🟢

nuno-vieira and others added 13 commits September 27, 2024 01:25
* Introduce new ViewContainerBuilder

* Add PollAttachmentView component

* Change to SwiftUI ENV

* Add `shouldShowOnlineIndicator` to turn off online presence in `ChatUserAvatarView`

* Fix small iOS 13 deprecation

* Add domain logic helpers to Poll

* Message Polls live updates

* Event.ownVotes workaround (Drop when fixed)

* Manage data races when voting on a poll in the message list

* Add haptic feedback when voting

* Make sure to update the latestVotes author avatar views

* Improve performance of Option List View by no recreating the item views everytime

* Improve flexibility of Option List View without compromising performance

* Make content of StackedUserAvatarsView public

* Re-structure Common Buttons Folder

* Add `CheckboxButton` as a common view

* Add vote ratio logic to `ChatChannelListItemView`

* Fix UI Glitches for option list item view when text is too big and avatar appears and disappears

* Extract more common logic to `Poll` domain model

* Add closed poll and winner option state logic

* Add subtitle text logic to `PollAttachmentView`

* Change winner logic to be the one and only one option with most votes

* Add channel list message preview text for polls

* Add poll quoted message text rendering

* Add View Results and End Button to the Poll Attachment View

* Fix poll option label width ui glitch

* Added End Poll functionality

* Add isOptionWinner and isOptionOneOfTheWinners to Poll

* Fix message with Polls not showing when long pressing

* Fix poll controller with incorrect data in message list

* Sort the `latestVotes` and `latestAnswers` in the LLC

* Add test coverage to Poll domain helpers

* Add Test Coverage to Poll Message Preview in Channel List

* Add test coverage to PollAttachmentView

* Add test coverage to disabling online indicator in ChatUserAvatarView

* Add test coverage to quoted poll

* Fix some existing snapshot tests

* Use UIStackView for Spacer() to avoid drawing

* Fix Xcode 14 Build

* Fix Poll AttachmentView Tests on CI

* Update CHANGELOG.md

* Update CHANGELOG.md

* Fix Xcode 14 Build, conflict with SwiftUI Spacer

* Revert "Change to SwiftUI ENV"

This reverts commit 6d9129a.

* Add documentation to ViewContainerBuilder

* Fix vale issues

* Fix using pin() instead of constraint() in docs
* Refactor PollResultsVC Section views to be more simple and flat hierarchy

* Fix bottom spacing in Poll Results Section Header

* Add comment buttons to `PollAttachmentView`

* Add comment to poll implementation

* Fix `poll.latestAnswers` being reset after poll event did not retreive the `latestAnswers` data

We should not treat optional `latestAnswers` as empty, since they have different meanings

* Add `PollCommentListVC` implementation

* Fix `PollVoteListQueryDTO.filterHash` using filterHash only instead of queryHash

This was causing the pollId to not be considered when fetching the DB votes

* Make diffable data sources more stable

* Fix first page of poll vote list resetting all votes

* Fix the default vote list sorting

* Add poll suggestions feature

* Add anonymous polls support

* Fix AlertsRouter docs

* Add test coverage to `PollCommentListVC`

* Add test coverage when poll comments are 0

* Add test coverage to allow suggestions

* Add test coverage to anonymous polls

* Re-record snapshots after renaming test file

* Fix snapshot on CI

* Update CHANGELOG.md

* Update CHANGELOG.md

* Update CHANGELOG.md

* Update Sources/StreamChatUI/ChatMessageList/Attachments/Poll/PollAttachmentView.swift

* Update Sources/StreamChatUI/ChatMessageList/Attachments/Poll/PollCommentListVC/PollCommentListSectionFooterView.swift

* Fix comments and suggestion buttons showing when poll is closed

* Update CHANGELOG.md

* Change alert titles to follow Apples guideline

* Improve comments view spacing

* Optimize a bit to check if a user has already a comment
* [Polls] Add `PollAttachmentView` + `ViewContainerBuilder` (#3374)

* Introduce new ViewContainerBuilder

* Add PollAttachmentView component

* Change to SwiftUI ENV

* Add `shouldShowOnlineIndicator` to turn off online presence in `ChatUserAvatarView`

* Fix small iOS 13 deprecation

* Add domain logic helpers to Poll

* Message Polls live updates

* Event.ownVotes workaround (Drop when fixed)

* Manage data races when voting on a poll in the message list

* Add haptic feedback when voting

* Make sure to update the latestVotes author avatar views

* Improve performance of Option List View by no recreating the item views everytime

* Improve flexibility of Option List View without compromising performance

* Make content of StackedUserAvatarsView public

* Re-structure Common Buttons Folder

* Add `CheckboxButton` as a common view

* Add vote ratio logic to `ChatChannelListItemView`

* Fix UI Glitches for option list item view when text is too big and avatar appears and disappears

* Extract more common logic to `Poll` domain model

* Add closed poll and winner option state logic

* Add subtitle text logic to `PollAttachmentView`

* Change winner logic to be the one and only one option with most votes

* Add channel list message preview text for polls

* Add poll quoted message text rendering

* Add View Results and End Button to the Poll Attachment View

* Fix poll option label width ui glitch

* Added End Poll functionality

* Add isOptionWinner and isOptionOneOfTheWinners to Poll

* Fix message with Polls not showing when long pressing

* Fix poll controller with incorrect data in message list

* Sort the `latestVotes` and `latestAnswers` in the LLC

* Add test coverage to Poll domain helpers

* Add Test Coverage to Poll Message Preview in Channel List

* Add test coverage to PollAttachmentView

* Add test coverage to disabling online indicator in ChatUserAvatarView

* Add test coverage to quoted poll

* Fix some existing snapshot tests

* Use UIStackView for Spacer() to avoid drawing

* Fix Xcode 14 Build

* Fix Poll AttachmentView Tests on CI

* Update CHANGELOG.md

* Update CHANGELOG.md

* Fix Xcode 14 Build, conflict with SwiftUI Spacer

* Revert "Change to SwiftUI ENV"

This reverts commit 6d9129a.

* Add documentation to ViewContainerBuilder

* Fix vale issues

* Fix using pin() instead of constraint() in docs

* [Polls] Add `PollResultsVC` (#3381)

* [Polls] Comments + Suggestions + Anonymous Polls + LLC Fixes (#3398)

* Refactor PollResultsVC Section views to be more simple and flat hierarchy

* Fix bottom spacing in Poll Results Section Header

* Add comment buttons to `PollAttachmentView`

* Add comment to poll implementation

* Fix `poll.latestAnswers` being reset after poll event did not retreive the `latestAnswers` data

We should not treat optional `latestAnswers` as empty, since they have different meanings

* Add `PollCommentListVC` implementation

* Fix `PollVoteListQueryDTO.filterHash` using filterHash only instead of queryHash

This was causing the pollId to not be considered when fetching the DB votes

* Make diffable data sources more stable

* Fix first page of poll vote list resetting all votes

* Fix the default vote list sorting

* Add poll suggestions feature

* Add anonymous polls support

* Fix AlertsRouter docs

* Add test coverage to `PollCommentListVC`

* Add test coverage when poll comments are 0

* Add test coverage to allow suggestions

* Add test coverage to anonymous polls

* Re-record snapshots after renaming test file

* Fix snapshot on CI

* Update CHANGELOG.md

* Update CHANGELOG.md

* Update CHANGELOG.md

* Update Sources/StreamChatUI/ChatMessageList/Attachments/Poll/PollAttachmentView.swift

* Update Sources/StreamChatUI/ChatMessageList/Attachments/Poll/PollCommentListVC/PollCommentListSectionFooterView.swift

* Fix comments and suggestion buttons showing when poll is closed

* Update CHANGELOG.md

* Change alert titles to follow Apples guideline

* Improve comments view spacing

* Optimize a bit to check if a user has already a comment

* Add poll creation action to composer if polls are enabled

* Add Poll Creation Views and UX

* Handle keyboard adjustment in the poll creation view

* Add actual if-statement support to ViewContainerBuilder

* Add Poll Creation View Styling

* Add poll creation section header view

* Add Poll Creation Feature Cell Styling

* Add Multiple Votes Feature Cell Data handling

* Improve data handling in PollCreationVC

* Add poll creation button

* Fix Poll Creation Memory Leaks + Add Poll Option Errors

* Implement poll option error indices

* Refactor Poll Creation View to Collection View

* Add views to components and appearance

* Implement keyboard management in Poll Creation VC

* Implementation of discarding poll changes

* Add poll alert error if creation fails

* Fix basic features not being persisted

* Add localization to the views

* Add for polls feature support configuration

* Add Poll Creation View test coverage

* Update CHANGELOG.md

* Fix test_canCreatePoll_whenOptionsError_shouldReturnFalse test

* [CI] Snapshots (#3434)

Co-authored-by: Stream Bot <[email protected]>

* Fix maximum votes error not being cleared when multiple votes is disabled

* Change multiple votes keyboard to number bad

* Remove custom equatable implementation that is not required for PollFeatureType

* Remove yeetd-normal.pkg file?

* Fix adding duplicate options

* Disable swiftlint notification_center_detachment and switch_case_alignment

* Extract poll creation input view height to a constant

---------

Co-authored-by: Stream SDK Bot <[email protected]>
Co-authored-by: Stream Bot <[email protected]>
… `layout` and `constraints`

The layout and constraints function would not work at all because applying constraints before adding a view to hierarchy is not possibl.e
Copy link
Contributor

@martinmitrevski martinmitrevski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of questions:

  • Did you test if everything works well in SwiftUI with this branch?
  • Why not include the polls docs in this PR?

@nuno-vieira nuno-vieira changed the title [Polls] Adds Polls UI Components + Introducing View Container Builder Adds Polls UI Components + Introducing View Container Builder Sep 27, 2024
@testableapple testableapple added the 🟢 QAed A PR that was QAed label Sep 30, 2024
Copy link
Contributor

@martinmitrevski martinmitrevski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That weird yeetd-normal.pkg file appeared again, please remove it. Other than that, looks good to me.

@nuno-vieira nuno-vieira merged commit bd028b8 into develop Oct 1, 2024
6 checks passed
@nuno-vieira nuno-vieira deleted the add/polls-ui-base branch October 1, 2024 23:13
Copy link

sonarqubecloud bot commented Oct 1, 2024

@Stream-SDK-Bot Stream-SDK-Bot mentioned this pull request Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✅ Feature An issue or PR related to a feature 🟢 QAed A PR that was QAed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants