-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: when in-app web content rendered, animate visibility of inline…
… View (#724) Co-authored-by: Ahmed Ali <[email protected]>
- Loading branch information
1 parent
4c3182b
commit 5d39cb6
Showing
4 changed files
with
88 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import Foundation | ||
import UIKit | ||
|
||
extension UIView { | ||
// Find the topmost superview in the view hierarchy. Probably the UIView of the UIViewController the UIView is nested in. | ||
func getRootSuperview() -> UIView? { | ||
guard var rootSuperview = superview else { | ||
return nil // no superview, return nil early. | ||
} | ||
|
||
while true { | ||
if let nextLevelSuperview = rootSuperview.superview { | ||
rootSuperview = nextLevelSuperview | ||
} else { | ||
return rootSuperview | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
Tests/MessagingInApp/Extensions/UIViewExtensionsTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
@testable import CioMessagingInApp | ||
import Foundation | ||
import SharedTests | ||
import XCTest | ||
|
||
class UIViewExtensionsTest: UnitTest { | ||
func test_getRootSuperview_givenNoSuperview_expectNil() { | ||
let givenView = UIView() | ||
|
||
XCTAssertNil(givenView.getRootSuperview()) | ||
} | ||
|
||
func test_getRootSuperview_givenSuperview_expectSuperview() { | ||
let givenView = UIView() | ||
let givenSuperview = UIView() | ||
givenSuperview.addSubview(givenView) | ||
|
||
XCTAssertEqual(givenView.getRootSuperview(), givenSuperview) | ||
} | ||
|
||
func test_getRootSuperview_givenMultipleLevelsOfNesting_expectRootSuperview() { | ||
let givenView = UIView() | ||
let givenSuperview = UIView() | ||
let givenRootSuperview = UIView() | ||
givenSuperview.addSubview(givenView) | ||
givenRootSuperview.addSubview(givenSuperview) | ||
|
||
XCTAssertEqual(givenView.getRootSuperview(), givenRootSuperview) | ||
} | ||
} |