From e66d0ce742c2da33443b7ee4ebc8efeb354b3ee8 Mon Sep 17 00:00:00 2001 From: PangMo5 Date: Sun, 30 May 2021 18:35:00 +0900 Subject: [PATCH] add ParallaxHeaderScrollView --- JellyfinPlayer.xcodeproj/project.pbxproj | 8 +++- .../Extensions/ParallaxHeaderScrollView.swift | 44 +++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 JellyfinPlayer/Extensions/ParallaxHeaderScrollView.swift diff --git a/JellyfinPlayer.xcodeproj/project.pbxproj b/JellyfinPlayer.xcodeproj/project.pbxproj index 8f7c94ec..89d913bf 100644 --- a/JellyfinPlayer.xcodeproj/project.pbxproj +++ b/JellyfinPlayer.xcodeproj/project.pbxproj @@ -47,6 +47,7 @@ 621338932660107500A81A2A /* String++.swift in Sources */ = {isa = PBXBuildFile; fileRef = 621338922660107500A81A2A /* String++.swift */; }; 62133895266096EF00A81A2A /* LibraryListViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62133894266096EF00A81A2A /* LibraryListViewModel.swift */; }; 621338B32660A07800A81A2A /* LazyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 621338B22660A07800A81A2A /* LazyView.swift */; }; + 6225FCCB2663841E00E067F6 /* ParallaxHeaderScrollView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6225FCCA2663841E00E067F6 /* ParallaxHeaderScrollView.swift */; }; 6273DD43265F4195009C1D0B /* Moya in Frameworks */ = {isa = PBXBuildFile; productRef = 6273DD42265F4195009C1D0B /* Moya */; }; 6273DD45265F4195009C1D0B /* CombineMoya in Frameworks */ = {isa = PBXBuildFile; productRef = 6273DD44265F4195009C1D0B /* CombineMoya */; }; 6273DD48265F41B3009C1D0B /* JellyfinAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6273DD47265F41B3009C1D0B /* JellyfinAPI.swift */; }; @@ -116,6 +117,7 @@ 621338922660107500A81A2A /* String++.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String++.swift"; sourceTree = ""; }; 62133894266096EF00A81A2A /* LibraryListViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LibraryListViewModel.swift; sourceTree = ""; }; 621338B22660A07800A81A2A /* LazyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LazyView.swift; sourceTree = ""; }; + 6225FCCA2663841E00E067F6 /* ParallaxHeaderScrollView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParallaxHeaderScrollView.swift; sourceTree = ""; }; 6273DD47265F41B3009C1D0B /* JellyfinAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JellyfinAPI.swift; sourceTree = ""; }; 6273DD4D265F47B2009C1D0B /* LibrarySearchViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LibrarySearchViewModel.swift; sourceTree = ""; }; AE8C3153265D60BF008AA076 /* SettingsModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsModel.swift; sourceTree = ""; }; @@ -218,6 +220,7 @@ 53892771263C8C6F0035E14B /* LoadingView.swift */, 621338B22660A07800A81A2A /* LazyView.swift */, 621338922660107500A81A2A /* String++.swift */, + 6225FCCA2663841E00E067F6 /* ParallaxHeaderScrollView.swift */, ); path = Extensions; sourceTree = ""; @@ -370,6 +373,7 @@ 5377CBFE263B596B003A4E83 /* PersistenceController.swift in Sources */, 5389276E263C25100035E14B /* ContinueWatchingView.swift in Sources */, 535BAE9F2649E569005FA86D /* ItemView.swift in Sources */, + 6225FCCB2663841E00E067F6 /* ParallaxHeaderScrollView.swift in Sources */, 53F8377D265FF67C00F456B3 /* VideoPlayerSettingsView.swift in Sources */, 53987CA426572C1300E7EA70 /* SeasonItemView.swift in Sources */, 53192D5D265AA78A008A4215 /* DeviceProfileBuilder.swift in Sources */, @@ -531,7 +535,7 @@ CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 29; DEVELOPMENT_ASSET_PATHS = ""; - DEVELOPMENT_TEAM = 9R8RREG67J; + DEVELOPMENT_TEAM = 4BHXT8RHFR; ENABLE_BITCODE = NO; ENABLE_PREVIEWS = YES; EXCLUDED_ARCHS = ""; @@ -558,7 +562,7 @@ CURRENT_PROJECT_VERSION = 29; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_ASSET_PATHS = ""; - DEVELOPMENT_TEAM = 9R8RREG67J; + DEVELOPMENT_TEAM = 4BHXT8RHFR; ENABLE_BITCODE = NO; ENABLE_PREVIEWS = YES; EXCLUDED_ARCHS = ""; diff --git a/JellyfinPlayer/Extensions/ParallaxHeaderScrollView.swift b/JellyfinPlayer/Extensions/ParallaxHeaderScrollView.swift new file mode 100644 index 00000000..1c57ffe8 --- /dev/null +++ b/JellyfinPlayer/Extensions/ParallaxHeaderScrollView.swift @@ -0,0 +1,44 @@ +// +// ParallaxHeaderScrollView.swift +// JellyfinPlayer +// +// Created by PangMo5 on 2021/05/30. +// + +import Foundation +import SwiftUI + +struct ParallaxHeaderScrollView: View { + var header: Header + var staticOverlayView: StaticOverlayView + var overlayAlignment: Alignment + var headerHeight: CGFloat + var content: () -> Content + + init(header: Header, + staticOverlayView: StaticOverlayView, + overlayAlignment: Alignment = .center, + headerHeight: CGFloat, + content: @escaping () -> Content) + { + self.header = header + self.staticOverlayView = staticOverlayView + self.overlayAlignment = overlayAlignment + self.headerHeight = headerHeight + self.content = content + } + + var body: some View { + ScrollView { + GeometryReader { proxy in + let yOffset = proxy.frame(in: .global).minY > 0 ? -proxy.frame(in: .global).minY : 0 + header + .frame(width: proxy.size.width, height: proxy.size.height - yOffset) + .overlay(staticOverlayView, alignment: overlayAlignment) + .offset(y: yOffset) + } + .frame(height: headerHeight) + content() + } + } +}