Skip to content

Commit c2ea4b6

Browse files
committed
refactoring
1 parent 8cbe709 commit c2ea4b6

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

Sources/swiftui-loop-videoplayer/protocol/LoopPlayerViewProtocol.swift

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,28 @@ public extension LoopPlayerViewProtocol{
4646
makeErrorView(view, error: error)
4747
}
4848

49+
/// Constructs an error view and adds it to the specified view if an error is present.
50+
/// - Parameters:
51+
/// - view: The view to which the error message view will be added.
52+
/// - error: The optional error which, if present, triggers the creation and addition of an error-specific view.
4953
@MainActor
50-
func makeErrorView(_ view: View, error: VPErrors?){
54+
func makeErrorView(_ view: View, error: VPErrors?) {
5155
if let error = error {
52-
5356
let errorView = errorTpl(error, settings.errorColor, settings.errorFontSize)
54-
55-
5657
view.addSubview(errorView)
57-
5858
activateFullScreenConstraints(for: errorView, in: view)
5959
}
6060
}
61-
61+
62+
/// Adds a subview to a given view and activates full-screen constraints on the subview within the parent view.
63+
/// - Parameters:
64+
/// - view: The parent view to which the subview will be added.
65+
/// - subView: The subview that will be added to the parent view.
66+
@MainActor
67+
func compose(_ view: View, _ subView: View) {
68+
view.addSubview(subView)
69+
activateFullScreenConstraints(for: subView, in: view)
70+
}
6271
}
6372

6473
#if os(iOS) || os(tvOS)

Sources/swiftui-loop-videoplayer/view/loop/ios/LoopPlayerViewIOS.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ struct LoopPlayerViewIOS: UIViewRepresentable, LoopPlayerViewProtocol {
4949

5050
if let asset{
5151
let player: LoopingPlayerUIView = createPlayerView(context: context, asset: asset)
52-
container.addSubview(player)
53-
activateFullScreenConstraints(for: player, in: container)
52+
compose(container, player)
5453
}
5554

5655
makeErrorView(container, error: error)

Sources/swiftui-loop-videoplayer/view/loop/mac/LoopPlayerViewMacOS.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ struct LoopPlayerViewMacOS: NSViewRepresentable, LoopPlayerViewProtocol {
4444

4545
if let asset{
4646
let player: LoopingPlayerNSView = createPlayerView(context: context, asset: asset)
47-
container.addSubview(player)
48-
activateFullScreenConstraints(for: player, in: container)
47+
compose(container, player)
4948
}
5049

5150
makeErrorView(container, error: error)

0 commit comments

Comments
 (0)