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

[CIS-528] Add connection status banner to DemoApp #970

Merged
merged 4 commits into from
Apr 15, 2021

Conversation

dmigach
Copy link
Contributor

@dmigach dmigach commented Apr 9, 2021

Mostly this change is about:

  • Adding a view for displaying the banner
  • Fixing an issue with internetIsOfflineError that prevented web socket client from reconnecting
  • Fixing URLSession configuration to make reconnection logic work
  • Implementing banner logic in DemoApp
  • Rehauling navigation in DemoApp a bit to support presenting banner on any screen
    banner

@codecov
Copy link

codecov bot commented Apr 9, 2021

Codecov Report

Merging #970 (bfa4aca) into main (d8f43bb) will increase coverage by 0.06%.
The diff coverage is 100.00%.

❗ Current head bfa4aca differs from pull request most recent head bbe17ae. Consider uploading reports for the commit bbe17ae to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##             main     #970      +/-   ##
==========================================
+ Coverage   89.62%   89.68%   +0.06%     
==========================================
  Files         210      211       +1     
  Lines        8739     8772      +33     
==========================================
+ Hits         7832     7867      +35     
+ Misses        907      905       -2     
Flag Coverage Δ
llc-tests 89.68% <100.00%> (+0.06%) ⬆️
llc-tests-ios12 85.88% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
Sources/StreamChat/ChatClient.swift 96.58% <100.00%> (ø)
...nternetConnection/Error+InternetNotAvailable.swift 100.00% <100.00%> (ø)
Sources/StreamChat/Utils/Cached.swift 76.47% <0.00%> (-5.89%) ⬇️
Sources/StreamChat/Database/DTOs/MessageDTO.swift 95.44% <0.00%> (-0.24%) ⬇️
Sources/StreamChat/Models/Channel.swift 73.91% <0.00%> (ø)
Sources/StreamChat/Models/Message.swift 88.09% <0.00%> (ø)
Sources/StreamChat/Utils/CoreDataLazy.swift 87.50% <0.00%> (ø)
Sources/StreamChat/Database/DTOs/ChannelDTO.swift 98.95% <0.00%> (+<0.01%) ⬆️
...ocketClient/Engine/URLSessionWebSocketEngine.swift 53.48% <0.00%> (+16.27%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fc0c534...bbe17ae. Read the comment docs.

import UIKit

final class DemoAppCoordinator {
static var shared: DemoAppCoordinator!
Copy link
Contributor Author

@dmigach dmigach Apr 9, 2021

Choose a reason for hiding this comment

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

It is this ugly for several reasons:

  • Initial nav controller lives in a storyboard
  • LoginViewController needs that to present Chat
  • We throw out LogicViewController as soon as we present Chat

Copy link
Contributor

Choose a reason for hiding this comment

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

If it's ugly why don't you fix it? 🤔 🤷‍♂️

Copy link
Contributor Author

@dmigach dmigach Apr 13, 2021

Choose a reason for hiding this comment

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

What I meant is that we don't have much choice here, so it's ugly comparing to conventional coordinators.
Or do you mean fixing the reasons I enumerated? I believe you mentioned something about storyboard being used on purpose

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reworked it

@dmigach dmigach force-pushed the CIS-528-connection-status-banner branch from 63922f4 to 4a0b0a3 Compare April 9, 2021 07:52
@VojtaStavik VojtaStavik changed the title WIP CIS-528 Add connection status banner to DemoApp [CIS-528] Add connection status banner to DemoApp Apr 9, 2021
@b-onc b-onc marked this pull request as draft April 9, 2021 08:52
@dmigach dmigach force-pushed the CIS-528-connection-status-banner branch from 90c45a1 to a870c06 Compare April 13, 2021 08:06
@dmigach dmigach marked this pull request as ready for review April 13, 2021 08:08
@dmigach dmigach requested a review from VojtaStavik April 13, 2021 08:08
@dmigach dmigach force-pushed the CIS-528-connection-status-banner branch 2 times, most recently from 4e9f08c to 1fc3ad6 Compare April 13, 2021 09:22
Copy link
Contributor

@VojtaStavik VojtaStavik left a comment

Choose a reason for hiding this comment

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

Looks good 👍 I left a couple of comments and questions...

config.waitsForConnectivity = true
config.waitsForConnectivity = false
Copy link
Contributor

Choose a reason for hiding this comment

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

This change should be covered by a test since it's a requirement for the system to work correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a test

@VojtaStavik
Copy link
Contributor

WHAT? Almost all my comments disappeared 😭

Comment on lines 11 to 19
override func didMoveToSuperview() {
super.didMoveToSuperview()
setUpLayout()
defaultAppearance()
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This a pattern from the SDK and I don't think we should use it here. The SDK for example takes care of the fact that this is called just once, which here doesn't happen. I think it's better to call these methods from a method which is guaranteed to be called just once.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now it's called once from init


addSubview(label)

translatesAutoresizingMaskIntoConstraints = false
Copy link
Contributor

Choose a reason for hiding this comment

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

The view's superview should decide about this, not the view itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reworked

Comment on lines 49 to 62
func attachToTopViewIfNeeded() {
guard let topView = navigationController.topViewController?.view,
topView != bannerView.superview else { return }

topView.addSubview(bannerView)

let guide = topView.safeAreaLayoutGuide
NSLayoutConstraint.activate(
[
bannerView.topAnchor.constraint(equalTo: guide.topAnchor)
]
)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than messing up with the view, can't we just add the banner to the navbar view?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now it works like this. I was having doubts on this approach when I first considered how to implement it because it is based on an assumption that navbar has clipsToBounds == false and also that it has the highest Z position, but probably it should be fine for the DemoApp. Anyway it's easy to rework if there will be issues

import UIKit

final class DemoAppCoordinator {
static var shared: DemoAppCoordinator!
Copy link
Contributor

Choose a reason for hiding this comment

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

If it's ugly why don't you fix it? 🤔 🤷‍♂️

Copy link
Contributor

@VojtaStavik VojtaStavik left a comment

Choose a reason for hiding this comment

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

Great 🎉

@dmigach dmigach force-pushed the CIS-528-connection-status-banner branch from bfa4aca to bbe17ae Compare April 14, 2021 16:07
@VojtaStavik
Copy link
Contributor

@dmigach please merge when you're ready 👍

@dmigach dmigach merged commit 123223f into main Apr 15, 2021
@dmigach dmigach deleted the CIS-528-connection-status-banner branch April 15, 2021 07:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants