Skip to content

Commit fa70945

Browse files
committedJun 2, 2022
Added automaticallyAdjustsContentInsets to YouTubePlayer Configuration
1 parent 96b831c commit fa70945

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed
 

‎Sources/Configuration/YouTubePlayer+Configuration.swift

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ public extension YouTubePlayer {
1515
/// - Note: This property is excluded from encoding
1616
public var isUserInteractionEnabled: Bool?
1717

18+
/// A Boolean value indicating if safe area insets should be added automatically to content insets
19+
/// - Note: This property is excluded from encoding
20+
public var automaticallyAdjustsContentInsets: Bool?
21+
1822
/// A Boolean value that indicates whether HTML5 videos can play Picture in Picture.
1923
/// - Note: This property is excluded from encoding
2024
public var allowsPictureInPictureMediaPlayback: Bool?
@@ -97,6 +101,7 @@ public extension YouTubePlayer {
97101
/// Creates a new instance of `YouTubePlayer.Configuration`
98102
public init(
99103
isUserInteractionEnabled: Bool? = nil,
104+
automaticallyAdjustsContentInsets: Bool? = nil,
100105
allowsPictureInPictureMediaPlayback: Bool? = nil,
101106
autoPlay: Bool? = nil,
102107
captionLanguage: String? = nil,
@@ -118,6 +123,7 @@ public extension YouTubePlayer {
118123
customUserAgent: String? = nil
119124
) {
120125
self.isUserInteractionEnabled = isUserInteractionEnabled
126+
self.automaticallyAdjustsContentInsets = automaticallyAdjustsContentInsets
121127
self.allowsPictureInPictureMediaPlayback = allowsPictureInPictureMediaPlayback
122128
self.autoPlay = autoPlay
123129
self.captionLanguage = captionLanguage

‎Sources/WebView/YouTubePlayerWebView+LoadPlayer.swift

+12
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ extension YouTubePlayerWebView {
5656
self.configuration.allowsPictureInPictureMediaPlayback = self.player
5757
.configuration
5858
.allowsPictureInPictureMediaPlayback ?? true
59+
// Update contentInsetAdjustmentBehavior
60+
self.scrollView.contentInsetAdjustmentBehavior = self.player
61+
.configuration
62+
.automaticallyAdjustsContentInsets
63+
.flatMap { $0 ? .automatic : .never }
64+
?? .automatic
65+
#else
66+
// Update automaticallyAdjustsContentInsets
67+
self.enclosingScrollView?.automaticallyAdjustsContentInsets = self.player
68+
.configuration
69+
.automaticallyAdjustsContentInsets
70+
?? true
5971
#endif
6072
// Set custom user agent
6173
self.customUserAgent = self.player.configuration.customUserAgent

0 commit comments

Comments
 (0)