├── .gitignore ├── Examples ├── Assets.xcassets │ ├── AccentColor.colorset │ │ └── Contents.json │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── Contents.json │ └── photo.imageset │ │ ├── 799D7BF6-CBD8-4409-BE54-863D25D4FC45.jpeg │ │ └── Contents.json ├── ContentView.swift ├── RefresherTest.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ ├── IDEWorkspaceChecks.plist │ │ └── swiftpm │ │ └── Package.resolved └── RefresherTestApp.swift ├── LICENSE ├── Package.resolved ├── Package.swift ├── Package@swift-5.8.swift ├── README.md ├── Sources └── Refresher │ ├── BlurView.swift │ ├── DefaultRefreshView.swift │ ├── Math.swift │ ├── OffsetReader.swift │ ├── RefreshSpinner.swift │ ├── Refresher.swift │ └── ScrollView+Extensions.swift └── images ├── 1.gif ├── 2.gif ├── 3.gif ├── 4.gif └── 5.gif /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | /.build 3 | /Packages 4 | /*.xcodeproj 5 | xcuserdata/ 6 | DerivedData/ 7 | .swiftpm/config/registries.json 8 | .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata 9 | .netrc 10 | .swiftpm 11 | -------------------------------------------------------------------------------- /Examples/Assets.xcassets/AccentColor.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "idiom" : "universal" 5 | } 6 | ], 7 | "info" : { 8 | "author" : "xcode", 9 | "version" : 1 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Examples/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "scale" : "2x", 6 | "size" : "20x20" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "scale" : "3x", 11 | "size" : "20x20" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "scale" : "2x", 16 | "size" : "29x29" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "scale" : "3x", 21 | "size" : "29x29" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "scale" : "2x", 26 | "size" : "40x40" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "scale" : "3x", 31 | "size" : "40x40" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "scale" : "2x", 36 | "size" : "60x60" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "scale" : "3x", 41 | "size" : "60x60" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "scale" : "1x", 46 | "size" : "20x20" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "scale" : "2x", 51 | "size" : "20x20" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "scale" : "1x", 56 | "size" : "29x29" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "scale" : "2x", 61 | "size" : "29x29" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "scale" : "1x", 66 | "size" : "40x40" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "scale" : "2x", 71 | "size" : "40x40" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "scale" : "1x", 76 | "size" : "76x76" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "scale" : "2x", 81 | "size" : "76x76" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "scale" : "2x", 86 | "size" : "83.5x83.5" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "scale" : "1x", 91 | "size" : "1024x1024" 92 | }, 93 | { 94 | "idiom" : "mac", 95 | "scale" : "1x", 96 | "size" : "16x16" 97 | }, 98 | { 99 | "idiom" : "mac", 100 | "scale" : "2x", 101 | "size" : "16x16" 102 | }, 103 | { 104 | "idiom" : "mac", 105 | "scale" : "1x", 106 | "size" : "32x32" 107 | }, 108 | { 109 | "idiom" : "mac", 110 | "scale" : "2x", 111 | "size" : "32x32" 112 | }, 113 | { 114 | "idiom" : "mac", 115 | "scale" : "1x", 116 | "size" : "128x128" 117 | }, 118 | { 119 | "idiom" : "mac", 120 | "scale" : "2x", 121 | "size" : "128x128" 122 | }, 123 | { 124 | "idiom" : "mac", 125 | "scale" : "1x", 126 | "size" : "256x256" 127 | }, 128 | { 129 | "idiom" : "mac", 130 | "scale" : "2x", 131 | "size" : "256x256" 132 | }, 133 | { 134 | "idiom" : "mac", 135 | "scale" : "1x", 136 | "size" : "512x512" 137 | }, 138 | { 139 | "idiom" : "mac", 140 | "scale" : "2x", 141 | "size" : "512x512" 142 | } 143 | ], 144 | "info" : { 145 | "author" : "xcode", 146 | "version" : 1 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /Examples/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Examples/Assets.xcassets/photo.imageset/799D7BF6-CBD8-4409-BE54-863D25D4FC45.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gh123man/SwiftUI-Refresher/5a24079e69e5ca62974ea0dbf4d8ef13ceedaad3/Examples/Assets.xcassets/photo.imageset/799D7BF6-CBD8-4409-BE54-863D25D4FC45.jpeg -------------------------------------------------------------------------------- /Examples/Assets.xcassets/photo.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "799D7BF6-CBD8-4409-BE54-863D25D4FC45.jpeg", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "author" : "xcode", 19 | "version" : 1 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Examples/ContentView.swift: -------------------------------------------------------------------------------- 1 | 2 | import SwiftUI 3 | import Refresher 4 | 5 | struct ContentView: View { 6 | 7 | @State var refreshed = 0 8 | @State var searchText = "" 9 | var body: some View { 10 | NavigationView { 11 | ScrollView { 12 | if #available(iOS 15.0, *) { 13 | Text("Searching for \(searchText)") 14 | .searchable(text: $searchText) 15 | .navigationTitle("Searchable") 16 | } 17 | VStack { 18 | Text("Hello, world!") 19 | Text("Refreshed: \(refreshed)") 20 | } 21 | NavigationLink(destination: DetailsView(style: .default)) { 22 | Text("Go to details") 23 | .padding() 24 | } 25 | 26 | NavigationLink(destination: DetailsOverlayView()) { 27 | Text("Go to details in overlay mode") 28 | .padding() 29 | } 30 | 31 | NavigationLink(destination: DetailsCustom()) { 32 | Text("Go to details with a custom spinner") 33 | .padding() 34 | } 35 | NavigationLink(destination: DetailsView(style: .system)) { 36 | Text("Go to details with system style animation") 37 | .padding() 38 | } 39 | NavigationLink(destination: DetailsView(style: .system, useImage: false)) { 40 | Text("Go to details with system style - no image") 41 | .padding() 42 | } 43 | NavigationLink(destination: DetailsSearch()) { 44 | Text("Go to details with system style and search bar in header") 45 | .padding() 46 | } 47 | ForEach((1...100), id: \.self) { _ in 48 | Text("asdf") 49 | } 50 | } 51 | .refresher { 52 | await Task.sleep(seconds: 2) 53 | refreshed += 1 54 | } 55 | .navigationTitle("Refresher") 56 | } 57 | } 58 | } 59 | 60 | struct DetailsSearch: View { 61 | @State var refreshed = 0 62 | @State var searchText = "" 63 | var body: some View { 64 | ScrollView { 65 | VStack { 66 | if #available(iOS 15.0, *) { 67 | Text("Searching for \(searchText)") 68 | .searchable(text: $searchText) 69 | .navigationTitle("Searchable") 70 | } 71 | Text("Details!") 72 | Text("Refreshed: \(refreshed)") 73 | } 74 | } 75 | .refresher(style: .system) { 76 | await Task.sleep(seconds: 2) 77 | refreshed += 1 78 | } 79 | .navigationBarTitle("", displayMode: .inline) 80 | } 81 | } 82 | 83 | struct DetailsView: View { 84 | @State var refreshed = 0 85 | var style: Style 86 | @State var useImage = true 87 | let rectangles = (0..<50).map { _ in CGFloat.random(in: 10..<50) } 88 | 89 | var body: some View { 90 | ScrollView { 91 | VStack { 92 | if useImage { 93 | Image("photo") 94 | .resizable() 95 | .aspectRatio(contentMode: .fill) 96 | } 97 | Text("Details!") 98 | Text("Refreshed: \(refreshed)") 99 | 100 | ScrollView(.horizontal, showsIndicators: false) { 101 | LazyHStack(spacing: 8) { 102 | ForEach(0..<10) { _ in 103 | Rectangle() 104 | .frame(width: 100, height: 100) 105 | } 106 | } 107 | .padding(.horizontal) 108 | } 109 | LazyVGrid(columns: Array(repeating: GridItem(.flexible(), spacing: 8), count: 3)) { 110 | ForEach(rectangles, id: \.self) { size in 111 | VStack { 112 | Rectangle() 113 | .frame(width: size, height: size) 114 | Text("text") 115 | } 116 | } 117 | } 118 | } 119 | } 120 | .refresher(style: style) { 121 | await Task.sleep(seconds: 2) 122 | refreshed += 1 123 | } 124 | .navigationBarTitle("", displayMode: .inline) 125 | } 126 | } 127 | 128 | struct DetailsOverlayView: View { 129 | @State var refreshed = 0 130 | var body: some View { 131 | ScrollView { 132 | VStack { 133 | GeometryReader { geometry in 134 | Image("photo") 135 | .resizable() 136 | .aspectRatio(contentMode: .fill) 137 | .frame(width: geometry.size.width, height: geometry.size.height) 138 | .offset(y: -geometry.frame(in: .global).minY) 139 | 140 | } 141 | .frame(height: 180) 142 | Text("Details!") 143 | Text("Refreshed: \(refreshed)") 144 | } 145 | } 146 | .refresher(style: .overlay) { 147 | await Task.sleep(seconds: 2) 148 | refreshed += 1 149 | } 150 | .navigationBarTitle("", displayMode: .inline) 151 | } 152 | } 153 | 154 | struct DetailsCustom: View { 155 | @State var refreshed = 0 156 | var body: some View { 157 | ScrollView { 158 | VStack { 159 | Image("photo") 160 | .resizable() 161 | .aspectRatio(contentMode: .fit) 162 | Text("Details!") 163 | Text("Refreshed: \(refreshed)") 164 | } 165 | } 166 | .refresher(refreshView: EmojiRefreshView.init ) { 167 | await Task.sleep(seconds: 1.5) 168 | refreshed += 1 169 | } 170 | .navigationBarTitle("", displayMode: .inline) 171 | } 172 | } 173 | 174 | public struct EmojiRefreshView: View { 175 | @Binding var state: RefresherState 176 | @State private var angle: Double = 0.0 177 | @State private var isAnimating = false 178 | 179 | var foreverAnimation: Animation { 180 | Animation.linear(duration: 1.0) 181 | .repeatForever(autoreverses: false) 182 | } 183 | 184 | public var body: some View { 185 | VStack { 186 | switch state.mode { 187 | case .notRefreshing: 188 | Text("🤪") 189 | .onAppear { 190 | isAnimating = false 191 | } 192 | case .pulling: 193 | Text("😯") 194 | .rotationEffect(.degrees(360 * state.dragPosition)) 195 | case .refreshing: 196 | Text("😂") 197 | .rotationEffect(.degrees(self.isAnimating ? 360.0 : 0.0)) 198 | .onAppear { 199 | withAnimation(foreverAnimation) { 200 | isAnimating = true 201 | } 202 | } 203 | } 204 | } 205 | .scaleEffect(2) 206 | } 207 | } 208 | 209 | struct ContentView_Previews: PreviewProvider { 210 | static var previews: some View { 211 | ContentView() 212 | DetailsView(style: .default) 213 | DetailsOverlayView() 214 | } 215 | } 216 | 217 | extension Task where Success == Never, Failure == Never { 218 | static func sleep(seconds: Double) async { 219 | let duration = UInt64(seconds * 1_000_000_000) 220 | try! await Task.sleep(nanoseconds: duration) 221 | } 222 | } 223 | -------------------------------------------------------------------------------- /Examples/RefresherTest.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 55; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | D3A3F302280CBFEF00BB28F1 /* RefresherTestApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3A3F2DA280CBFEE00BB28F1 /* RefresherTestApp.swift */; }; 11 | D3A3F303280CBFEF00BB28F1 /* RefresherTestApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3A3F2DA280CBFEE00BB28F1 /* RefresherTestApp.swift */; }; 12 | D3A3F304280CBFEF00BB28F1 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3A3F2DB280CBFEE00BB28F1 /* ContentView.swift */; }; 13 | D3A3F305280CBFEF00BB28F1 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3A3F2DB280CBFEE00BB28F1 /* ContentView.swift */; }; 14 | D3A3F306280CBFEF00BB28F1 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D3A3F2DC280CBFEF00BB28F1 /* Assets.xcassets */; }; 15 | D3A3F307280CBFEF00BB28F1 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D3A3F2DC280CBFEF00BB28F1 /* Assets.xcassets */; }; 16 | D3A3F333280F186C00BB28F1 /* Refresher in Frameworks */ = {isa = PBXBuildFile; productRef = D3A3F332280F186C00BB28F1 /* Refresher */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXContainerItemProxy section */ 20 | D3A3F2EF280CBFEF00BB28F1 /* PBXContainerItemProxy */ = { 21 | isa = PBXContainerItemProxy; 22 | containerPortal = D3A3F2D5280CBFEE00BB28F1 /* Project object */; 23 | proxyType = 1; 24 | remoteGlobalIDString = D3A3F2E0280CBFEF00BB28F1; 25 | remoteInfo = "RefresherTest (iOS)"; 26 | }; 27 | D3A3F2FB280CBFEF00BB28F1 /* PBXContainerItemProxy */ = { 28 | isa = PBXContainerItemProxy; 29 | containerPortal = D3A3F2D5280CBFEE00BB28F1 /* Project object */; 30 | proxyType = 1; 31 | remoteGlobalIDString = D3A3F2E6280CBFEF00BB28F1; 32 | remoteInfo = "RefresherTest (macOS)"; 33 | }; 34 | /* End PBXContainerItemProxy section */ 35 | 36 | /* Begin PBXFileReference section */ 37 | D3A3F2DA280CBFEE00BB28F1 /* RefresherTestApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RefresherTestApp.swift; sourceTree = ""; }; 38 | D3A3F2DB280CBFEE00BB28F1 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 39 | D3A3F2DC280CBFEF00BB28F1 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 40 | D3A3F2E1280CBFEF00BB28F1 /* RefresherTest.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = RefresherTest.app; sourceTree = BUILT_PRODUCTS_DIR; }; 41 | D3A3F2E7280CBFEF00BB28F1 /* RefresherTest.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = RefresherTest.app; sourceTree = BUILT_PRODUCTS_DIR; }; 42 | D3A3F2EE280CBFEF00BB28F1 /* Tests iOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Tests iOS.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 43 | D3A3F2FA280CBFEF00BB28F1 /* Tests macOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Tests macOS.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 44 | D3A3F331280F185E00BB28F1 /* Refresher */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = Refresher; path = ..; sourceTree = ""; }; 45 | /* End PBXFileReference section */ 46 | 47 | /* Begin PBXFrameworksBuildPhase section */ 48 | D3A3F2DE280CBFEF00BB28F1 /* Frameworks */ = { 49 | isa = PBXFrameworksBuildPhase; 50 | buildActionMask = 2147483647; 51 | files = ( 52 | D3A3F333280F186C00BB28F1 /* Refresher in Frameworks */, 53 | ); 54 | runOnlyForDeploymentPostprocessing = 0; 55 | }; 56 | D3A3F2E4280CBFEF00BB28F1 /* Frameworks */ = { 57 | isa = PBXFrameworksBuildPhase; 58 | buildActionMask = 2147483647; 59 | files = ( 60 | ); 61 | runOnlyForDeploymentPostprocessing = 0; 62 | }; 63 | D3A3F2EB280CBFEF00BB28F1 /* Frameworks */ = { 64 | isa = PBXFrameworksBuildPhase; 65 | buildActionMask = 2147483647; 66 | files = ( 67 | ); 68 | runOnlyForDeploymentPostprocessing = 0; 69 | }; 70 | D3A3F2F7280CBFEF00BB28F1 /* Frameworks */ = { 71 | isa = PBXFrameworksBuildPhase; 72 | buildActionMask = 2147483647; 73 | files = ( 74 | ); 75 | runOnlyForDeploymentPostprocessing = 0; 76 | }; 77 | /* End PBXFrameworksBuildPhase section */ 78 | 79 | /* Begin PBXGroup section */ 80 | D3A3F2D4280CBFEE00BB28F1 = { 81 | isa = PBXGroup; 82 | children = ( 83 | D3A3F2DA280CBFEE00BB28F1 /* RefresherTestApp.swift */, 84 | D3A3F2DB280CBFEE00BB28F1 /* ContentView.swift */, 85 | D3A3F2DC280CBFEF00BB28F1 /* Assets.xcassets */, 86 | D3A3F331280F185E00BB28F1 /* Refresher */, 87 | D3A3F31C280CC88500BB28F1 /* Packages */, 88 | D3A3F2E2280CBFEF00BB28F1 /* Products */, 89 | D3A3F321280CCA3300BB28F1 /* Frameworks */, 90 | ); 91 | sourceTree = ""; 92 | }; 93 | D3A3F2E2280CBFEF00BB28F1 /* Products */ = { 94 | isa = PBXGroup; 95 | children = ( 96 | D3A3F2E1280CBFEF00BB28F1 /* RefresherTest.app */, 97 | D3A3F2E7280CBFEF00BB28F1 /* RefresherTest.app */, 98 | D3A3F2EE280CBFEF00BB28F1 /* Tests iOS.xctest */, 99 | D3A3F2FA280CBFEF00BB28F1 /* Tests macOS.xctest */, 100 | ); 101 | name = Products; 102 | sourceTree = ""; 103 | }; 104 | D3A3F31C280CC88500BB28F1 /* Packages */ = { 105 | isa = PBXGroup; 106 | children = ( 107 | ); 108 | name = Packages; 109 | sourceTree = ""; 110 | }; 111 | D3A3F321280CCA3300BB28F1 /* Frameworks */ = { 112 | isa = PBXGroup; 113 | children = ( 114 | ); 115 | name = Frameworks; 116 | sourceTree = ""; 117 | }; 118 | /* End PBXGroup section */ 119 | 120 | /* Begin PBXNativeTarget section */ 121 | D3A3F2E0280CBFEF00BB28F1 /* RefresherTest (iOS) */ = { 122 | isa = PBXNativeTarget; 123 | buildConfigurationList = D3A3F30A280CBFEF00BB28F1 /* Build configuration list for PBXNativeTarget "RefresherTest (iOS)" */; 124 | buildPhases = ( 125 | D3A3F2DD280CBFEF00BB28F1 /* Sources */, 126 | D3A3F2DE280CBFEF00BB28F1 /* Frameworks */, 127 | D3A3F2DF280CBFEF00BB28F1 /* Resources */, 128 | ); 129 | buildRules = ( 130 | ); 131 | dependencies = ( 132 | ); 133 | name = "RefresherTest (iOS)"; 134 | packageProductDependencies = ( 135 | D3A3F332280F186C00BB28F1 /* Refresher */, 136 | ); 137 | productName = "RefresherTest (iOS)"; 138 | productReference = D3A3F2E1280CBFEF00BB28F1 /* RefresherTest.app */; 139 | productType = "com.apple.product-type.application"; 140 | }; 141 | D3A3F2E6280CBFEF00BB28F1 /* RefresherTest (macOS) */ = { 142 | isa = PBXNativeTarget; 143 | buildConfigurationList = D3A3F30D280CBFEF00BB28F1 /* Build configuration list for PBXNativeTarget "RefresherTest (macOS)" */; 144 | buildPhases = ( 145 | D3A3F2E3280CBFEF00BB28F1 /* Sources */, 146 | D3A3F2E4280CBFEF00BB28F1 /* Frameworks */, 147 | D3A3F2E5280CBFEF00BB28F1 /* Resources */, 148 | ); 149 | buildRules = ( 150 | ); 151 | dependencies = ( 152 | ); 153 | name = "RefresherTest (macOS)"; 154 | productName = "RefresherTest (macOS)"; 155 | productReference = D3A3F2E7280CBFEF00BB28F1 /* RefresherTest.app */; 156 | productType = "com.apple.product-type.application"; 157 | }; 158 | D3A3F2ED280CBFEF00BB28F1 /* Tests iOS */ = { 159 | isa = PBXNativeTarget; 160 | buildConfigurationList = D3A3F310280CBFEF00BB28F1 /* Build configuration list for PBXNativeTarget "Tests iOS" */; 161 | buildPhases = ( 162 | D3A3F2EA280CBFEF00BB28F1 /* Sources */, 163 | D3A3F2EB280CBFEF00BB28F1 /* Frameworks */, 164 | D3A3F2EC280CBFEF00BB28F1 /* Resources */, 165 | ); 166 | buildRules = ( 167 | ); 168 | dependencies = ( 169 | D3A3F2F0280CBFEF00BB28F1 /* PBXTargetDependency */, 170 | ); 171 | name = "Tests iOS"; 172 | productName = "Tests iOS"; 173 | productReference = D3A3F2EE280CBFEF00BB28F1 /* Tests iOS.xctest */; 174 | productType = "com.apple.product-type.bundle.ui-testing"; 175 | }; 176 | D3A3F2F9280CBFEF00BB28F1 /* Tests macOS */ = { 177 | isa = PBXNativeTarget; 178 | buildConfigurationList = D3A3F313280CBFEF00BB28F1 /* Build configuration list for PBXNativeTarget "Tests macOS" */; 179 | buildPhases = ( 180 | D3A3F2F6280CBFEF00BB28F1 /* Sources */, 181 | D3A3F2F7280CBFEF00BB28F1 /* Frameworks */, 182 | D3A3F2F8280CBFEF00BB28F1 /* Resources */, 183 | ); 184 | buildRules = ( 185 | ); 186 | dependencies = ( 187 | D3A3F2FC280CBFEF00BB28F1 /* PBXTargetDependency */, 188 | ); 189 | name = "Tests macOS"; 190 | productName = "Tests macOS"; 191 | productReference = D3A3F2FA280CBFEF00BB28F1 /* Tests macOS.xctest */; 192 | productType = "com.apple.product-type.bundle.ui-testing"; 193 | }; 194 | /* End PBXNativeTarget section */ 195 | 196 | /* Begin PBXProject section */ 197 | D3A3F2D5280CBFEE00BB28F1 /* Project object */ = { 198 | isa = PBXProject; 199 | attributes = { 200 | BuildIndependentTargetsInParallel = 1; 201 | LastSwiftUpdateCheck = 1330; 202 | LastUpgradeCheck = 1330; 203 | TargetAttributes = { 204 | D3A3F2E0280CBFEF00BB28F1 = { 205 | CreatedOnToolsVersion = 13.3.1; 206 | }; 207 | D3A3F2E6280CBFEF00BB28F1 = { 208 | CreatedOnToolsVersion = 13.3.1; 209 | }; 210 | D3A3F2ED280CBFEF00BB28F1 = { 211 | CreatedOnToolsVersion = 13.3.1; 212 | TestTargetID = D3A3F2E0280CBFEF00BB28F1; 213 | }; 214 | D3A3F2F9280CBFEF00BB28F1 = { 215 | CreatedOnToolsVersion = 13.3.1; 216 | TestTargetID = D3A3F2E6280CBFEF00BB28F1; 217 | }; 218 | }; 219 | }; 220 | buildConfigurationList = D3A3F2D8280CBFEE00BB28F1 /* Build configuration list for PBXProject "RefresherTest" */; 221 | compatibilityVersion = "Xcode 13.0"; 222 | developmentRegion = en; 223 | hasScannedForEncodings = 0; 224 | knownRegions = ( 225 | en, 226 | Base, 227 | ); 228 | mainGroup = D3A3F2D4280CBFEE00BB28F1; 229 | productRefGroup = D3A3F2E2280CBFEF00BB28F1 /* Products */; 230 | projectDirPath = ""; 231 | projectRoot = ""; 232 | targets = ( 233 | D3A3F2E0280CBFEF00BB28F1 /* RefresherTest (iOS) */, 234 | D3A3F2E6280CBFEF00BB28F1 /* RefresherTest (macOS) */, 235 | D3A3F2ED280CBFEF00BB28F1 /* Tests iOS */, 236 | D3A3F2F9280CBFEF00BB28F1 /* Tests macOS */, 237 | ); 238 | }; 239 | /* End PBXProject section */ 240 | 241 | /* Begin PBXResourcesBuildPhase section */ 242 | D3A3F2DF280CBFEF00BB28F1 /* Resources */ = { 243 | isa = PBXResourcesBuildPhase; 244 | buildActionMask = 2147483647; 245 | files = ( 246 | D3A3F306280CBFEF00BB28F1 /* Assets.xcassets in Resources */, 247 | ); 248 | runOnlyForDeploymentPostprocessing = 0; 249 | }; 250 | D3A3F2E5280CBFEF00BB28F1 /* Resources */ = { 251 | isa = PBXResourcesBuildPhase; 252 | buildActionMask = 2147483647; 253 | files = ( 254 | D3A3F307280CBFEF00BB28F1 /* Assets.xcassets in Resources */, 255 | ); 256 | runOnlyForDeploymentPostprocessing = 0; 257 | }; 258 | D3A3F2EC280CBFEF00BB28F1 /* Resources */ = { 259 | isa = PBXResourcesBuildPhase; 260 | buildActionMask = 2147483647; 261 | files = ( 262 | ); 263 | runOnlyForDeploymentPostprocessing = 0; 264 | }; 265 | D3A3F2F8280CBFEF00BB28F1 /* Resources */ = { 266 | isa = PBXResourcesBuildPhase; 267 | buildActionMask = 2147483647; 268 | files = ( 269 | ); 270 | runOnlyForDeploymentPostprocessing = 0; 271 | }; 272 | /* End PBXResourcesBuildPhase section */ 273 | 274 | /* Begin PBXSourcesBuildPhase section */ 275 | D3A3F2DD280CBFEF00BB28F1 /* Sources */ = { 276 | isa = PBXSourcesBuildPhase; 277 | buildActionMask = 2147483647; 278 | files = ( 279 | D3A3F304280CBFEF00BB28F1 /* ContentView.swift in Sources */, 280 | D3A3F302280CBFEF00BB28F1 /* RefresherTestApp.swift in Sources */, 281 | ); 282 | runOnlyForDeploymentPostprocessing = 0; 283 | }; 284 | D3A3F2E3280CBFEF00BB28F1 /* Sources */ = { 285 | isa = PBXSourcesBuildPhase; 286 | buildActionMask = 2147483647; 287 | files = ( 288 | D3A3F305280CBFEF00BB28F1 /* ContentView.swift in Sources */, 289 | D3A3F303280CBFEF00BB28F1 /* RefresherTestApp.swift in Sources */, 290 | ); 291 | runOnlyForDeploymentPostprocessing = 0; 292 | }; 293 | D3A3F2EA280CBFEF00BB28F1 /* Sources */ = { 294 | isa = PBXSourcesBuildPhase; 295 | buildActionMask = 2147483647; 296 | files = ( 297 | ); 298 | runOnlyForDeploymentPostprocessing = 0; 299 | }; 300 | D3A3F2F6280CBFEF00BB28F1 /* Sources */ = { 301 | isa = PBXSourcesBuildPhase; 302 | buildActionMask = 2147483647; 303 | files = ( 304 | ); 305 | runOnlyForDeploymentPostprocessing = 0; 306 | }; 307 | /* End PBXSourcesBuildPhase section */ 308 | 309 | /* Begin PBXTargetDependency section */ 310 | D3A3F2F0280CBFEF00BB28F1 /* PBXTargetDependency */ = { 311 | isa = PBXTargetDependency; 312 | target = D3A3F2E0280CBFEF00BB28F1 /* RefresherTest (iOS) */; 313 | targetProxy = D3A3F2EF280CBFEF00BB28F1 /* PBXContainerItemProxy */; 314 | }; 315 | D3A3F2FC280CBFEF00BB28F1 /* PBXTargetDependency */ = { 316 | isa = PBXTargetDependency; 317 | target = D3A3F2E6280CBFEF00BB28F1 /* RefresherTest (macOS) */; 318 | targetProxy = D3A3F2FB280CBFEF00BB28F1 /* PBXContainerItemProxy */; 319 | }; 320 | /* End PBXTargetDependency section */ 321 | 322 | /* Begin XCBuildConfiguration section */ 323 | D3A3F308280CBFEF00BB28F1 /* Debug */ = { 324 | isa = XCBuildConfiguration; 325 | buildSettings = { 326 | ALWAYS_SEARCH_USER_PATHS = NO; 327 | CLANG_ANALYZER_NONNULL = YES; 328 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 329 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; 330 | CLANG_ENABLE_MODULES = YES; 331 | CLANG_ENABLE_OBJC_ARC = YES; 332 | CLANG_ENABLE_OBJC_WEAK = YES; 333 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 334 | CLANG_WARN_BOOL_CONVERSION = YES; 335 | CLANG_WARN_COMMA = YES; 336 | CLANG_WARN_CONSTANT_CONVERSION = YES; 337 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 338 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 339 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 340 | CLANG_WARN_EMPTY_BODY = YES; 341 | CLANG_WARN_ENUM_CONVERSION = YES; 342 | CLANG_WARN_INFINITE_RECURSION = YES; 343 | CLANG_WARN_INT_CONVERSION = YES; 344 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 345 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 346 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 347 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 348 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 349 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 350 | CLANG_WARN_STRICT_PROTOTYPES = YES; 351 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 352 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 353 | CLANG_WARN_UNREACHABLE_CODE = YES; 354 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 355 | COPY_PHASE_STRIP = NO; 356 | DEBUG_INFORMATION_FORMAT = dwarf; 357 | ENABLE_STRICT_OBJC_MSGSEND = YES; 358 | ENABLE_TESTABILITY = YES; 359 | GCC_C_LANGUAGE_STANDARD = gnu11; 360 | GCC_DYNAMIC_NO_PIC = NO; 361 | GCC_NO_COMMON_BLOCKS = YES; 362 | GCC_OPTIMIZATION_LEVEL = 0; 363 | GCC_PREPROCESSOR_DEFINITIONS = ( 364 | "DEBUG=1", 365 | "$(inherited)", 366 | ); 367 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 368 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 369 | GCC_WARN_UNDECLARED_SELECTOR = YES; 370 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 371 | GCC_WARN_UNUSED_FUNCTION = YES; 372 | GCC_WARN_UNUSED_VARIABLE = YES; 373 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 374 | MTL_FAST_MATH = YES; 375 | ONLY_ACTIVE_ARCH = YES; 376 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 377 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 378 | }; 379 | name = Debug; 380 | }; 381 | D3A3F309280CBFEF00BB28F1 /* Release */ = { 382 | isa = XCBuildConfiguration; 383 | buildSettings = { 384 | ALWAYS_SEARCH_USER_PATHS = NO; 385 | CLANG_ANALYZER_NONNULL = YES; 386 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 387 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; 388 | CLANG_ENABLE_MODULES = YES; 389 | CLANG_ENABLE_OBJC_ARC = YES; 390 | CLANG_ENABLE_OBJC_WEAK = YES; 391 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 392 | CLANG_WARN_BOOL_CONVERSION = YES; 393 | CLANG_WARN_COMMA = YES; 394 | CLANG_WARN_CONSTANT_CONVERSION = YES; 395 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 396 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 397 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 398 | CLANG_WARN_EMPTY_BODY = YES; 399 | CLANG_WARN_ENUM_CONVERSION = YES; 400 | CLANG_WARN_INFINITE_RECURSION = YES; 401 | CLANG_WARN_INT_CONVERSION = YES; 402 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 403 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 404 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 405 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 406 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 407 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 408 | CLANG_WARN_STRICT_PROTOTYPES = YES; 409 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 410 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 411 | CLANG_WARN_UNREACHABLE_CODE = YES; 412 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 413 | COPY_PHASE_STRIP = NO; 414 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 415 | ENABLE_NS_ASSERTIONS = NO; 416 | ENABLE_STRICT_OBJC_MSGSEND = YES; 417 | GCC_C_LANGUAGE_STANDARD = gnu11; 418 | GCC_NO_COMMON_BLOCKS = YES; 419 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 420 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 421 | GCC_WARN_UNDECLARED_SELECTOR = YES; 422 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 423 | GCC_WARN_UNUSED_FUNCTION = YES; 424 | GCC_WARN_UNUSED_VARIABLE = YES; 425 | MTL_ENABLE_DEBUG_INFO = NO; 426 | MTL_FAST_MATH = YES; 427 | SWIFT_COMPILATION_MODE = wholemodule; 428 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 429 | }; 430 | name = Release; 431 | }; 432 | D3A3F30B280CBFEF00BB28F1 /* Debug */ = { 433 | isa = XCBuildConfiguration; 434 | buildSettings = { 435 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 436 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 437 | CODE_SIGN_STYLE = Automatic; 438 | CURRENT_PROJECT_VERSION = 1; 439 | DEVELOPMENT_TEAM = 79TGW25V5A; 440 | ENABLE_PREVIEWS = YES; 441 | GENERATE_INFOPLIST_FILE = YES; 442 | INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; 443 | INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; 444 | INFOPLIST_KEY_UILaunchScreen_Generation = YES; 445 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 446 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 447 | IPHONEOS_DEPLOYMENT_TARGET = 14.1; 448 | LD_RUNPATH_SEARCH_PATHS = ( 449 | "$(inherited)", 450 | "@executable_path/Frameworks", 451 | ); 452 | MARKETING_VERSION = 1.0; 453 | PRODUCT_BUNDLE_IDENTIFIER = bugtest.RefresherTest; 454 | PRODUCT_NAME = RefresherTest; 455 | SDKROOT = iphoneos; 456 | SWIFT_EMIT_LOC_STRINGS = YES; 457 | SWIFT_VERSION = 5.0; 458 | TARGETED_DEVICE_FAMILY = "1,2"; 459 | }; 460 | name = Debug; 461 | }; 462 | D3A3F30C280CBFEF00BB28F1 /* Release */ = { 463 | isa = XCBuildConfiguration; 464 | buildSettings = { 465 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 466 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 467 | CODE_SIGN_STYLE = Automatic; 468 | CURRENT_PROJECT_VERSION = 1; 469 | DEVELOPMENT_TEAM = 79TGW25V5A; 470 | ENABLE_PREVIEWS = YES; 471 | GENERATE_INFOPLIST_FILE = YES; 472 | INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; 473 | INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; 474 | INFOPLIST_KEY_UILaunchScreen_Generation = YES; 475 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 476 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 477 | IPHONEOS_DEPLOYMENT_TARGET = 14.1; 478 | LD_RUNPATH_SEARCH_PATHS = ( 479 | "$(inherited)", 480 | "@executable_path/Frameworks", 481 | ); 482 | MARKETING_VERSION = 1.0; 483 | PRODUCT_BUNDLE_IDENTIFIER = bugtest.RefresherTest; 484 | PRODUCT_NAME = RefresherTest; 485 | SDKROOT = iphoneos; 486 | SWIFT_EMIT_LOC_STRINGS = YES; 487 | SWIFT_VERSION = 5.0; 488 | TARGETED_DEVICE_FAMILY = "1,2"; 489 | VALIDATE_PRODUCT = YES; 490 | }; 491 | name = Release; 492 | }; 493 | D3A3F30E280CBFEF00BB28F1 /* Debug */ = { 494 | isa = XCBuildConfiguration; 495 | buildSettings = { 496 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 497 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 498 | CODE_SIGN_ENTITLEMENTS = macOS/macOS.entitlements; 499 | CODE_SIGN_STYLE = Automatic; 500 | COMBINE_HIDPI_IMAGES = YES; 501 | CURRENT_PROJECT_VERSION = 1; 502 | DEVELOPMENT_TEAM = 79TGW25V5A; 503 | ENABLE_HARDENED_RUNTIME = YES; 504 | ENABLE_PREVIEWS = YES; 505 | GENERATE_INFOPLIST_FILE = YES; 506 | INFOPLIST_KEY_NSHumanReadableCopyright = ""; 507 | LD_RUNPATH_SEARCH_PATHS = ( 508 | "$(inherited)", 509 | "@executable_path/../Frameworks", 510 | ); 511 | MACOSX_DEPLOYMENT_TARGET = 12.3; 512 | MARKETING_VERSION = 1.0; 513 | PRODUCT_BUNDLE_IDENTIFIER = bugtest.RefresherTest; 514 | PRODUCT_NAME = RefresherTest; 515 | SDKROOT = macosx; 516 | SWIFT_EMIT_LOC_STRINGS = YES; 517 | SWIFT_VERSION = 5.0; 518 | }; 519 | name = Debug; 520 | }; 521 | D3A3F30F280CBFEF00BB28F1 /* Release */ = { 522 | isa = XCBuildConfiguration; 523 | buildSettings = { 524 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 525 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 526 | CODE_SIGN_ENTITLEMENTS = macOS/macOS.entitlements; 527 | CODE_SIGN_STYLE = Automatic; 528 | COMBINE_HIDPI_IMAGES = YES; 529 | CURRENT_PROJECT_VERSION = 1; 530 | DEVELOPMENT_TEAM = 79TGW25V5A; 531 | ENABLE_HARDENED_RUNTIME = YES; 532 | ENABLE_PREVIEWS = YES; 533 | GENERATE_INFOPLIST_FILE = YES; 534 | INFOPLIST_KEY_NSHumanReadableCopyright = ""; 535 | LD_RUNPATH_SEARCH_PATHS = ( 536 | "$(inherited)", 537 | "@executable_path/../Frameworks", 538 | ); 539 | MACOSX_DEPLOYMENT_TARGET = 12.3; 540 | MARKETING_VERSION = 1.0; 541 | PRODUCT_BUNDLE_IDENTIFIER = bugtest.RefresherTest; 542 | PRODUCT_NAME = RefresherTest; 543 | SDKROOT = macosx; 544 | SWIFT_EMIT_LOC_STRINGS = YES; 545 | SWIFT_VERSION = 5.0; 546 | }; 547 | name = Release; 548 | }; 549 | D3A3F311280CBFEF00BB28F1 /* Debug */ = { 550 | isa = XCBuildConfiguration; 551 | buildSettings = { 552 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 553 | CODE_SIGN_STYLE = Automatic; 554 | CURRENT_PROJECT_VERSION = 1; 555 | DEVELOPMENT_TEAM = 79TGW25V5A; 556 | GENERATE_INFOPLIST_FILE = YES; 557 | IPHONEOS_DEPLOYMENT_TARGET = 15.4; 558 | MARKETING_VERSION = 1.0; 559 | PRODUCT_BUNDLE_IDENTIFIER = "bugtest.Tests-iOS"; 560 | PRODUCT_NAME = "$(TARGET_NAME)"; 561 | SDKROOT = iphoneos; 562 | SWIFT_EMIT_LOC_STRINGS = NO; 563 | SWIFT_VERSION = 5.0; 564 | TARGETED_DEVICE_FAMILY = "1,2"; 565 | TEST_TARGET_NAME = "RefresherTest (iOS)"; 566 | }; 567 | name = Debug; 568 | }; 569 | D3A3F312280CBFEF00BB28F1 /* Release */ = { 570 | isa = XCBuildConfiguration; 571 | buildSettings = { 572 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 573 | CODE_SIGN_STYLE = Automatic; 574 | CURRENT_PROJECT_VERSION = 1; 575 | DEVELOPMENT_TEAM = 79TGW25V5A; 576 | GENERATE_INFOPLIST_FILE = YES; 577 | IPHONEOS_DEPLOYMENT_TARGET = 15.4; 578 | MARKETING_VERSION = 1.0; 579 | PRODUCT_BUNDLE_IDENTIFIER = "bugtest.Tests-iOS"; 580 | PRODUCT_NAME = "$(TARGET_NAME)"; 581 | SDKROOT = iphoneos; 582 | SWIFT_EMIT_LOC_STRINGS = NO; 583 | SWIFT_VERSION = 5.0; 584 | TARGETED_DEVICE_FAMILY = "1,2"; 585 | TEST_TARGET_NAME = "RefresherTest (iOS)"; 586 | VALIDATE_PRODUCT = YES; 587 | }; 588 | name = Release; 589 | }; 590 | D3A3F314280CBFEF00BB28F1 /* Debug */ = { 591 | isa = XCBuildConfiguration; 592 | buildSettings = { 593 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 594 | CODE_SIGN_STYLE = Automatic; 595 | CURRENT_PROJECT_VERSION = 1; 596 | DEVELOPMENT_TEAM = 79TGW25V5A; 597 | GENERATE_INFOPLIST_FILE = YES; 598 | MACOSX_DEPLOYMENT_TARGET = 12.3; 599 | MARKETING_VERSION = 1.0; 600 | PRODUCT_BUNDLE_IDENTIFIER = "bugtest.Tests-macOS"; 601 | PRODUCT_NAME = "$(TARGET_NAME)"; 602 | SDKROOT = macosx; 603 | SWIFT_EMIT_LOC_STRINGS = NO; 604 | SWIFT_VERSION = 5.0; 605 | TEST_TARGET_NAME = "RefresherTest (macOS)"; 606 | }; 607 | name = Debug; 608 | }; 609 | D3A3F315280CBFEF00BB28F1 /* Release */ = { 610 | isa = XCBuildConfiguration; 611 | buildSettings = { 612 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 613 | CODE_SIGN_STYLE = Automatic; 614 | CURRENT_PROJECT_VERSION = 1; 615 | DEVELOPMENT_TEAM = 79TGW25V5A; 616 | GENERATE_INFOPLIST_FILE = YES; 617 | MACOSX_DEPLOYMENT_TARGET = 12.3; 618 | MARKETING_VERSION = 1.0; 619 | PRODUCT_BUNDLE_IDENTIFIER = "bugtest.Tests-macOS"; 620 | PRODUCT_NAME = "$(TARGET_NAME)"; 621 | SDKROOT = macosx; 622 | SWIFT_EMIT_LOC_STRINGS = NO; 623 | SWIFT_VERSION = 5.0; 624 | TEST_TARGET_NAME = "RefresherTest (macOS)"; 625 | }; 626 | name = Release; 627 | }; 628 | /* End XCBuildConfiguration section */ 629 | 630 | /* Begin XCConfigurationList section */ 631 | D3A3F2D8280CBFEE00BB28F1 /* Build configuration list for PBXProject "RefresherTest" */ = { 632 | isa = XCConfigurationList; 633 | buildConfigurations = ( 634 | D3A3F308280CBFEF00BB28F1 /* Debug */, 635 | D3A3F309280CBFEF00BB28F1 /* Release */, 636 | ); 637 | defaultConfigurationIsVisible = 0; 638 | defaultConfigurationName = Release; 639 | }; 640 | D3A3F30A280CBFEF00BB28F1 /* Build configuration list for PBXNativeTarget "RefresherTest (iOS)" */ = { 641 | isa = XCConfigurationList; 642 | buildConfigurations = ( 643 | D3A3F30B280CBFEF00BB28F1 /* Debug */, 644 | D3A3F30C280CBFEF00BB28F1 /* Release */, 645 | ); 646 | defaultConfigurationIsVisible = 0; 647 | defaultConfigurationName = Release; 648 | }; 649 | D3A3F30D280CBFEF00BB28F1 /* Build configuration list for PBXNativeTarget "RefresherTest (macOS)" */ = { 650 | isa = XCConfigurationList; 651 | buildConfigurations = ( 652 | D3A3F30E280CBFEF00BB28F1 /* Debug */, 653 | D3A3F30F280CBFEF00BB28F1 /* Release */, 654 | ); 655 | defaultConfigurationIsVisible = 0; 656 | defaultConfigurationName = Release; 657 | }; 658 | D3A3F310280CBFEF00BB28F1 /* Build configuration list for PBXNativeTarget "Tests iOS" */ = { 659 | isa = XCConfigurationList; 660 | buildConfigurations = ( 661 | D3A3F311280CBFEF00BB28F1 /* Debug */, 662 | D3A3F312280CBFEF00BB28F1 /* Release */, 663 | ); 664 | defaultConfigurationIsVisible = 0; 665 | defaultConfigurationName = Release; 666 | }; 667 | D3A3F313280CBFEF00BB28F1 /* Build configuration list for PBXNativeTarget "Tests macOS" */ = { 668 | isa = XCConfigurationList; 669 | buildConfigurations = ( 670 | D3A3F314280CBFEF00BB28F1 /* Debug */, 671 | D3A3F315280CBFEF00BB28F1 /* Release */, 672 | ); 673 | defaultConfigurationIsVisible = 0; 674 | defaultConfigurationName = Release; 675 | }; 676 | /* End XCConfigurationList section */ 677 | 678 | /* Begin XCSwiftPackageProductDependency section */ 679 | D3A3F332280F186C00BB28F1 /* Refresher */ = { 680 | isa = XCSwiftPackageProductDependency; 681 | productName = Refresher; 682 | }; 683 | /* End XCSwiftPackageProductDependency section */ 684 | }; 685 | rootObject = D3A3F2D5280CBFEE00BB28F1 /* Project object */; 686 | } 687 | -------------------------------------------------------------------------------- /Examples/RefresherTest.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Examples/RefresherTest.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Examples/RefresherTest.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved: -------------------------------------------------------------------------------- 1 | { 2 | "pins" : [ 3 | { 4 | "identity" : "swiftui-introspect", 5 | "kind" : "remoteSourceControl", 6 | "location" : "https://github.com/siteline/SwiftUI-Introspect.git", 7 | "state" : { 8 | "revision" : "668a65735751432b640260c56dfa621cec568368", 9 | "version" : "1.2.0" 10 | } 11 | }, 12 | { 13 | "identity" : "swiftui-renderlock", 14 | "kind" : "remoteSourceControl", 15 | "location" : "https://github.com/gh123man/SwiftUI-RenderLock", 16 | "state" : { 17 | "revision" : "11ca0d472dad0053cb8b29701ea3f108b9aa2304", 18 | "version" : "1.0.2" 19 | } 20 | } 21 | ], 22 | "version" : 2 23 | } 24 | -------------------------------------------------------------------------------- /Examples/RefresherTestApp.swift: -------------------------------------------------------------------------------- 1 | // 2 | // RefresherTestApp.swift 3 | // Shared 4 | // 5 | // Created by Brian Floersch on 4/17/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | @main 11 | struct RefresherTestApp: App { 12 | var body: some Scene { 13 | WindowGroup { 14 | ContentView() 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Brian Floersch 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Package.resolved: -------------------------------------------------------------------------------- 1 | { 2 | "pins" : [ 3 | { 4 | "identity" : "swiftui-introspect", 5 | "kind" : "remoteSourceControl", 6 | "location" : "https://github.com/siteline/SwiftUI-Introspect.git", 7 | "state" : { 8 | "revision" : "668a65735751432b640260c56dfa621cec568368", 9 | "version" : "1.2.0" 10 | } 11 | }, 12 | { 13 | "identity" : "swiftui-renderlock", 14 | "kind" : "remoteSourceControl", 15 | "location" : "https://github.com/gh123man/SwiftUI-RenderLock", 16 | "state" : { 17 | "revision" : "11ca0d472dad0053cb8b29701ea3f108b9aa2304", 18 | "version" : "1.0.2" 19 | } 20 | } 21 | ], 22 | "version" : 2 23 | } 24 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version: 5.9 2 | // The swift-tools-version declares the minimum version of Swift required to build this package. 3 | 4 | import PackageDescription 5 | 6 | let package = Package( 7 | name: "Refresher", 8 | platforms: [ 9 | .iOS(.v14), 10 | .visionOS(.v1) 11 | ], 12 | products: [ 13 | // Products define the executables and libraries a package produces, and make them visible to other packages. 14 | .library( 15 | name: "Refresher", 16 | targets: ["Refresher"]), 17 | ], 18 | dependencies: [ 19 | // Dependencies declare other packages that this package depends on. 20 | .package(url: "https://github.com/siteline/SwiftUI-Introspect.git", from: "1.2.0"), 21 | .package(url: "https://github.com/gh123man/SwiftUI-RenderLock", from: "1.0.2"), 22 | ], 23 | targets: [ 24 | // Targets are the basic building blocks of a package. A target can define a module or a test suite. 25 | // Targets can depend on other targets in this package, and on products in packages this package depends on. 26 | .target( 27 | name: "Refresher", 28 | dependencies: [ 29 | .product( 30 | name: "SwiftUIIntrospect", 31 | package: "SwiftUI-Introspect"), 32 | .product( 33 | name: "RenderLock", 34 | package: "SwiftUI-RenderLock") 35 | ] 36 | ), 37 | ] 38 | ) 39 | -------------------------------------------------------------------------------- /Package@swift-5.8.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version: 5.8 2 | // The swift-tools-version declares the minimum version of Swift required to build this package. 3 | 4 | import PackageDescription 5 | 6 | let package = Package( 7 | name: "Refresher", 8 | platforms: [ 9 | .iOS(.v14) 10 | ], 11 | products: [ 12 | // Products define the executables and libraries a package produces, and make them visible to other packages. 13 | .library( 14 | name: "Refresher", 15 | targets: ["Refresher"]), 16 | ], 17 | dependencies: [ 18 | // Dependencies declare other packages that this package depends on. 19 | .package(url: "https://github.com/siteline/SwiftUI-Introspect.git", from: "1.2.0"), 20 | .package(url: "https://github.com/gh123man/SwiftUI-RenderLock", from: "1.0.2"), 21 | ], 22 | targets: [ 23 | // Targets are the basic building blocks of a package. A target can define a module or a test suite. 24 | // Targets can depend on other targets in this package, and on products in packages this package depends on. 25 | .target( 26 | name: "Refresher", 27 | dependencies: [ 28 | .product( 29 | name: "SwiftUIIntrospect", 30 | package: "SwiftUI-Introspect"), 31 | .product( 32 | name: "RenderLock", 33 | package: "SwiftUI-RenderLock") 34 | ] 35 | ), 36 | ] 37 | ) 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Refresher 2 | 3 | A customizable, native SwiftUI refresh control for iOS 14+ 4 | 5 | ## Why? 6 | 7 | - the native SwiftUI refresh control only works on iOS 15+ 8 | - the native UIKit refresh control works with ugly wrappers, but has buggy behavior with navigation views 9 | - I needed a refresh control that could accomodate an overlay (such as appearing on top of a static image) 10 | - This one is very customizable 11 | 12 | ## See it in action 13 | If you want to see it in a real app, check out [dateit](https://apps.apple.com/us/app/dateit/id1610780514) 14 | 15 | Also works well with [ScrollViewLoader](https://github.com/gh123man/ScrollViewLoader) 16 | 17 | ## Usage 18 | First add the package to your project. 19 | 20 | ```swift 21 | import Refresher 22 | 23 | struct DetailsView: View { 24 | @State var refreshed = 0 25 | 26 | var body: some View { 27 | ScrollView { 28 | Text("Details!") 29 | Text("Refreshed: \(refreshed)") 30 | } 31 | .refresher { // Called when pulled to refresh 32 | await Task.sleep(seconds: 2) 33 | refreshed += 1 34 | } 35 | } 36 | } 37 | ``` 38 | 39 | ## Features 40 | - `async`/`await` compatible - even on iOS 14 41 | - completion callback also supported for `DispatchQueue` operations 42 | - `.default` and `.system` styles (see below for details) 43 | - customizable refresh spinner (see below for example) 44 | 45 | 46 | ## Examples and usage 47 | 48 | See: [Examples](/Examples/) for a full sample project with multiple implementations 49 | 50 | ### Navigation view 51 | 52 | ![Navigation](/images/1.gif) 53 | 54 | `Refresher` plays nice with both Navigation views and navigation subviews. 55 | 56 | ![Subview](/images/3.gif) 57 | 58 | ### Detail view with overlay 59 | 60 | `Refresher` supports an overlay mode to show a refresh indicator over fixed position content 61 | 62 | `.refresher(overlay: true)` 63 | 64 | ![Overlay](/images/2.gif) 65 | 66 | ### System style 67 | `Refresher`'s default animation is designed to be more flexible than the system animation style. If you want `Refresher` to behave more like they system refresh control, you can change the style: 68 | 69 | ```swift 70 | .refresher(style: .system) { done in 71 | ``` 72 | 73 | ![System](/images/5.gif) 74 | 75 | ## Customization 76 | 77 | Refresher can take a custom spinner view. Your custom view will get a binding instances of the refresher state that contains useful properties for managing animations and translations. Here is a custom spinner that shows an emoji: 78 | 79 | ```swift 80 | public struct EmojiRefreshView: View { 81 | @Binding var state: RefresherState 82 | @State private var angle: Double = 0.0 83 | @State private var isAnimating = false 84 | 85 | var foreverAnimation: Animation { 86 | Animation.linear(duration: 1.0) 87 | .repeatForever(autoreverses: false) 88 | } 89 | 90 | public var body: some View { 91 | VStack { 92 | switch state.mode { 93 | case .notRefreshing: 94 | Text("🤪") 95 | .onAppear { 96 | isAnimating = false 97 | } 98 | case .pulling: 99 | Text("😯") 100 | .rotationEffect(.degrees(360 * state.dragPosition)) 101 | case .refreshing: 102 | Text("😂") 103 | .rotationEffect(.degrees(self.isAnimating ? 360.0 : 0.0)) 104 | .onAppear { 105 | withAnimation(foreverAnimation) { 106 | isAnimating = true 107 | } 108 | } 109 | } 110 | } 111 | .scaleEffect(2) 112 | } 113 | } 114 | ``` 115 | 116 | Add the custom refresherView: 117 | ```swift 118 | .refresher(refreshView: EmojiRefreshView.init ) { done in 119 | ``` 120 | 121 | ![Custom](/images/4.gif) 122 | 123 | ## Completion handler 124 | 125 | If you prefer to call a completion to stop the refresher: 126 | ```swift 127 | .refresher(style: .system) { done in 128 | DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1)) { 129 | refreshed += 1 130 | done() // Call done to stop the refresher 131 | } 132 | } 133 | ``` 134 | -------------------------------------------------------------------------------- /Sources/Refresher/BlurView.swift: -------------------------------------------------------------------------------- 1 | #if canImport(UIKit) 2 | import Foundation 3 | import SwiftUI 4 | import UIKit 5 | 6 | struct BlurView: UIViewRepresentable { 7 | public typealias UIViewType = UIVisualEffectView 8 | 9 | let style: UIBlurEffect.Style 10 | 11 | init(style: UIBlurEffect.Style = .dark) { 12 | self.style = style 13 | } 14 | 15 | func makeUIView(context: Context) -> UIVisualEffectView { 16 | return UIVisualEffectView(effect: UIBlurEffect(style: self.style)) 17 | } 18 | 19 | func updateUIView(_ uiView: UIVisualEffectView, context: Context) { 20 | uiView.effect = UIBlurEffect(style: self.style) 21 | } 22 | } 23 | #endif 24 | -------------------------------------------------------------------------------- /Sources/Refresher/DefaultRefreshView.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | import SwiftUI 3 | 4 | struct UIActivityView: UIViewRepresentable { 5 | var style: UIActivityIndicatorView.Style = .medium 6 | @Binding var isAnimating: Bool 7 | 8 | 9 | func makeUIView(context: Context) -> UIActivityIndicatorView { 10 | let v = UIActivityIndicatorView(style: style) 11 | v.hidesWhenStopped = false 12 | return v 13 | } 14 | 15 | func updateUIView(_ uiView: UIActivityIndicatorView, context: Context) { 16 | if isAnimating { 17 | uiView.startAnimating() 18 | } else { 19 | uiView.stopAnimating() 20 | } 21 | } 22 | } 23 | 24 | public struct DefaultRefreshView: View { 25 | @Binding var state: RefresherState 26 | @State var isAnimating = false 27 | 28 | public init(state: Binding) { 29 | self._state = state 30 | } 31 | 32 | @Environment(\.colorScheme) var colorScheme 33 | 34 | public var body: some View { 35 | if state.style == .system || state.style == .system2 { 36 | VStack { 37 | UIActivityView(style: .large, isAnimating: $isAnimating) 38 | .rotationEffect(.degrees(state.mode == .pulling ? 360 * state.dragPosition : 360)) 39 | .onChange(of: state.mode) { newMode in 40 | isAnimating = newMode != .pulling 41 | } 42 | } 43 | } else { 44 | VStack { 45 | UIActivityView(isAnimating: $isAnimating) 46 | .padding(5) 47 | .rotationEffect(.degrees(state.mode == .pulling ? 360 * state.dragPosition : 360)) 48 | .onChange(of: state.mode) { newMode in 49 | isAnimating = newMode != .pulling 50 | } 51 | } 52 | .background(BlurView(style: colorScheme == .dark ? .dark : .light)) 53 | .clipShape(Circle()) 54 | 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Sources/Refresher/Math.swift: -------------------------------------------------------------------------------- 1 | #if canImport(UIKit) 2 | import Foundation 3 | import UIKit 4 | 5 | func lerp(from: CGFloat, to: CGFloat, by: CGFloat) -> CGFloat { 6 | return from * (1 - by) + to * by 7 | } 8 | 9 | func normalize(from min: CGFloat, to max: CGFloat, by val: CGFloat) -> CGFloat { 10 | let v = (val - min) / (max - min) 11 | return v < 0 ? 0 : v > 1 ? 1 : v 12 | } 13 | #endif 14 | -------------------------------------------------------------------------------- /Sources/Refresher/OffsetReader.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | import SwiftUI 3 | 4 | struct OffsetReader: View { 5 | var onChange: (CGFloat) -> () 6 | 7 | public var body: some View { 8 | GeometryReader { geometry in 9 | Color.clear 10 | .preference(key: OffsetPreferenceKey.self, 11 | value: geometry.frame(in: .global).minY) 12 | .onPreferenceChange(OffsetPreferenceKey.self) { offset in 13 | onChange(offset) 14 | } 15 | } 16 | } 17 | } 18 | 19 | private struct OffsetPreferenceKey: PreferenceKey { 20 | static var defaultValue = CGFloat.zero 21 | 22 | static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) { 23 | value = nextValue() 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Sources/Refresher/RefreshSpinner.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | import SwiftUI 3 | 4 | public struct RefreshSpinnerView: View { 5 | var offScreenPoint: CGFloat 6 | var pullClipPoint: CGFloat 7 | var mode: RefreshMode 8 | var stopPoint: CGFloat 9 | var refreshHoldPoint: CGFloat 10 | var refreshView: RefreshView 11 | 12 | @Binding var headerInset: CGFloat 13 | var refreshAt: CGFloat 14 | 15 | func offset(_ y: CGFloat) -> CGFloat { 16 | let percent = normalize(from: 0, to: refreshAt, by: y) 17 | if case .refreshing = mode { 18 | return lerp(from: refreshHoldPoint, to: stopPoint, by: percent) 19 | } 20 | let normalizedPercent = normalize(from: pullClipPoint, to: 1, by: percent) 21 | if normalizedPercent == 0 { 22 | // Since the spinner view moves with the scrollview, move it 23 | // backwards until we are ready to start the refreshing animation 24 | return -headerInset + offScreenPoint * (1 + percent) 25 | } 26 | return lerp(from: -headerInset + offScreenPoint, to: stopPoint, by: normalizedPercent) 27 | } 28 | 29 | public var body: some View { 30 | VStack(alignment: .leading, spacing: 0) { 31 | GeometryReader { geometry in 32 | refreshView 33 | .frame(maxWidth: .infinity) 34 | .position(x: geometry.size.width / 2, y: offset(geometry.frame(in: .global).minY - headerInset)) 35 | } 36 | } 37 | } 38 | } 39 | 40 | public struct SystemStyleRefreshSpinner: View { 41 | var opacityClipPoint: CGFloat 42 | 43 | var state: RefresherState 44 | var position: CGFloat 45 | var refreshHoldPoint: CGFloat 46 | var refreshView: RefreshView 47 | 48 | public var body: some View { 49 | VStack(alignment: .leading, spacing: 0) { 50 | GeometryReader { geometry in 51 | refreshView 52 | .frame(maxWidth: .infinity) 53 | .position(x: geometry.size.width / 2, y: -position + refreshHoldPoint) 54 | .opacity(state.modeAnimated == .refreshing ? 1 : normalize(from: opacityClipPoint, to: 1, by: state.dragPosition)) 55 | .animation(.easeInOut(duration: 0.2), value: state.modeAnimated == .notRefreshing) 56 | } 57 | } 58 | } 59 | } 60 | 61 | public struct System2StyleRefreshSpinner: View { 62 | var opacityClipPoint: CGFloat 63 | 64 | var state: RefresherState 65 | var refreshHoldPoint: CGFloat 66 | var refreshView: RefreshView 67 | 68 | func offset() -> CGFloat { 69 | switch state.mode { 70 | case .refreshing, .notRefreshing: 71 | return refreshHoldPoint 72 | default: return lerp(from: 0, to: refreshHoldPoint, by: state.dragPosition) 73 | } 74 | } 75 | 76 | public var body: some View { 77 | VStack(alignment: .leading, spacing: 0) { 78 | GeometryReader { geometry in 79 | refreshView 80 | .frame(maxWidth: .infinity) 81 | .position(x: geometry.size.width / 2, y: offset()) 82 | .opacity(state.modeAnimated == .refreshing ? 1 : normalize(from: opacityClipPoint, to: 1, by: state.dragPosition)) 83 | .animation(.easeInOut(duration: 0.2), value: state.modeAnimated == .notRefreshing) 84 | } 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /Sources/Refresher/Refresher.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | import SwiftUI 3 | import SwiftUIIntrospect 4 | import RenderLock 5 | 6 | public typealias RefreshAction = (_ completion: @escaping () -> ()) -> () 7 | public typealias AsyncRefreshAction = () async -> () 8 | 9 | public struct Config { 10 | /// Drag distance needed to trigger a refresh 11 | public var refreshAt: CGFloat 12 | 13 | /// Max height of the spacer for the refresh spinner to sit while refreshing 14 | public var headerShimMaxHeight: CGFloat 15 | 16 | /// Offset where the spinner stops moving after draging 17 | public var defaultSpinnerSpinnerStopPoint: CGFloat 18 | 19 | /// Off screen start point for the spinner (relative to the top of the screen) 20 | /// TIP: set this to the max height of your spinner view if using a custom spinner. 21 | public var defaultSpinnerOffScreenPoint: CGFloat 22 | 23 | /// How far you have to pull (from 0 - 1) for the spinner to start moving 24 | public var defaultSpinnerPullClipPoint: CGFloat 25 | 26 | /// How far you have to pull (from 0 - 1) for the spinner to start becoming visible 27 | public var systemSpinnerOpacityClipPoint: CGFloat 28 | 29 | /// How long to hold the spinner before dismissing (a small delay is a nice UX if the refresh is VERY fast) 30 | public var holdTime: DispatchTimeInterval 31 | 32 | /// How long to wait before allowing the next refresh 33 | public var cooldown: DispatchTimeInterval 34 | 35 | /// How close to resting position the scrollview has to move in order to allow the next refresh (finger must also be released from screen) 36 | public var resetPoint: CGFloat 37 | 38 | public init( 39 | refreshAt: CGFloat = 90, 40 | headerShimMaxHeight: CGFloat = 75, 41 | defaultSpinnerSpinnerStopPoint: CGFloat = -50, 42 | defaultSpinnerOffScreenPoint: CGFloat = -50, 43 | defaultSpinnerPullClipPoint: CGFloat = 0.1, 44 | systemSpinnerOpacityClipPoint: CGFloat = 0.2, 45 | holdTime: DispatchTimeInterval = .milliseconds(300), 46 | cooldown: DispatchTimeInterval = .milliseconds(500), 47 | resetPoint: CGFloat = 5 48 | ) { 49 | self.refreshAt = refreshAt 50 | self.defaultSpinnerSpinnerStopPoint = defaultSpinnerSpinnerStopPoint 51 | self.headerShimMaxHeight = headerShimMaxHeight 52 | self.defaultSpinnerOffScreenPoint = defaultSpinnerOffScreenPoint 53 | self.defaultSpinnerPullClipPoint = defaultSpinnerPullClipPoint 54 | self.systemSpinnerOpacityClipPoint = systemSpinnerOpacityClipPoint 55 | self.holdTime = holdTime 56 | self.cooldown = cooldown 57 | self.resetPoint = resetPoint 58 | } 59 | } 60 | 61 | public enum Style { 62 | /// Spinner pulls down and centers on a padding view above the scrollview 63 | case `default` 64 | 65 | /// Mimic the system refresh controller as close as possible 66 | case system 67 | case system2 68 | 69 | /// Overlay the spinner onto the cotained view - good for static images 70 | case overlay 71 | } 72 | 73 | public enum RefreshMode { 74 | case notRefreshing 75 | case pulling 76 | case refreshing 77 | } 78 | 79 | public struct RefresherState { 80 | /// Updated without animation - NOTE: Both modes are always updated in sequence (this one is first) 81 | public var mode: RefreshMode = .notRefreshing 82 | 83 | /// Updated with animation (this one is second) 84 | public var modeAnimated: RefreshMode = .notRefreshing 85 | 86 | /// Value from 0 - 1. 0 is resting state, 1 is refresh trigger point - use this value for custom translations 87 | public var dragPosition: CGFloat = 0 88 | 89 | /// the configuration style - useful if you want your custom spinner to change behavior based on the style 90 | public let style: Style 91 | } 92 | 93 | 94 | public struct RefreshableScrollView: View { 95 | let axes: Axis.Set 96 | let showsIndicators: Bool 97 | let content: Content 98 | let refreshAction: RefreshAction 99 | var refreshView: (Binding) -> RefreshView 100 | 101 | @State private var headerInset: CGFloat = 1000000 // Somewhere far off screen 102 | @State var state: RefresherState 103 | @State var distance: CGFloat = 0 104 | @State var rawDistance: CGFloat = 0 105 | @State var renderLock = false 106 | private let style: Style 107 | private let config: Config 108 | 109 | @State private var uiScrollView: UIScrollView? 110 | @State private var isRefresherVisible = true 111 | @State private var isFingerDown = false 112 | @State private var canRefresh = true 113 | 114 | init( 115 | axes: Axis.Set = .vertical, 116 | showsIndicators: Bool = true, 117 | refreshAction: @escaping RefreshAction, 118 | style: Style, 119 | config: Config, 120 | refreshView: @escaping (Binding) -> RefreshView, 121 | content: Content 122 | ) { 123 | self.axes = axes 124 | self.showsIndicators = showsIndicators 125 | self.refreshAction = refreshAction 126 | self.refreshView = refreshView 127 | self.content = content 128 | self.style = style 129 | self.config = config 130 | self._state = .init(wrappedValue: RefresherState(style: style)) 131 | } 132 | 133 | private var refreshHeaderOffset: CGFloat { 134 | switch state.style { 135 | case .default, .system: 136 | if case .refreshing = state.modeAnimated { 137 | return config.headerShimMaxHeight * (1 - state.dragPosition) 138 | } 139 | case .system2: 140 | switch state.modeAnimated { 141 | case .pulling: 142 | return config.headerShimMaxHeight * (state.dragPosition) 143 | case .refreshing: 144 | return config.headerShimMaxHeight 145 | default: break 146 | } 147 | default: break 148 | } 149 | 150 | return 0 151 | } 152 | 153 | private var isTracking: Bool { 154 | guard let scrollView = uiScrollView else { return false } 155 | return scrollView.isTracking 156 | } 157 | 158 | private var showRefreshControls: Bool { 159 | return isFingerDown || isRefresherVisible 160 | } 161 | 162 | @ViewBuilder 163 | private var refreshSpinner: some View { 164 | if style == .default || style == .overlay { 165 | RefreshSpinnerView(offScreenPoint: config.defaultSpinnerOffScreenPoint, 166 | pullClipPoint: config.defaultSpinnerPullClipPoint, 167 | mode: state.modeAnimated, 168 | stopPoint: config.defaultSpinnerSpinnerStopPoint, 169 | refreshHoldPoint: config.headerShimMaxHeight / 2, 170 | refreshView: refreshView($state), 171 | headerInset: $headerInset, 172 | refreshAt: config.refreshAt) 173 | .opacity(showRefreshControls ? 1 : 0) 174 | } 175 | } 176 | 177 | @ViewBuilder 178 | private var systemStyleRefreshSpinner: some View { 179 | if style == .system { 180 | SystemStyleRefreshSpinner(opacityClipPoint: config.systemSpinnerOpacityClipPoint, 181 | state: state, 182 | position: distance, 183 | refreshHoldPoint: config.headerShimMaxHeight / 2, 184 | refreshView: refreshView($state)) 185 | .opacity(showRefreshControls ? 1 : 0) 186 | } 187 | } 188 | 189 | @ViewBuilder 190 | private var system2StyleRefreshSpinner: some View { 191 | if style == .system2 { 192 | System2StyleRefreshSpinner(opacityClipPoint: config.systemSpinnerOpacityClipPoint, 193 | state: state, 194 | refreshHoldPoint: config.headerShimMaxHeight / 2, 195 | refreshView: refreshView($state)) 196 | .opacity(showRefreshControls ? 1 : 0) 197 | } 198 | } 199 | 200 | public var body: some View { 201 | // The ordering of views and operations here is very important - things break 202 | // in very strange ways between iOS 14 and iOS 15. 203 | GeometryReader { globalGeometry in 204 | ScrollView(axes, showsIndicators: showsIndicators) { 205 | ZStack(alignment: .top) { 206 | OffsetReader { val in 207 | offsetChanged(val) 208 | } 209 | systemStyleRefreshSpinner 210 | system2StyleRefreshSpinner 211 | 212 | // Content wrapper with refresh banner 213 | VStack(spacing: 0) { 214 | content 215 | .renderLocked(with: $renderLock) 216 | .offset(y: refreshHeaderOffset) 217 | } 218 | // renders over content 219 | refreshSpinner 220 | } 221 | } 222 | .introspect(.scrollView, on: .iOS(.v14, .v15, .v16, .v17, .v18)) { scrollView in 223 | DispatchQueue.main.async { 224 | uiScrollView = scrollView 225 | } 226 | } 227 | .onChange(of: globalGeometry.frame(in: .global)) { val in 228 | headerInset = val.minY 229 | } 230 | .onAppear { 231 | DispatchQueue.main.async { 232 | headerInset = globalGeometry.frame(in: .global).minY 233 | } 234 | } 235 | } 236 | } 237 | 238 | private func offsetChanged(_ val: CGFloat) { 239 | isFingerDown = isTracking 240 | distance = val - headerInset 241 | state.dragPosition = normalize(from: 0, to: config.refreshAt, by: distance) 242 | 243 | // If the refresh state has settled, we are not touching the screen, and the offset has settled, we can signal the view to update itself. 244 | if canRefresh, !isFingerDown, distance <= 0 { 245 | renderLock = false 246 | } 247 | 248 | guard canRefresh else { 249 | canRefresh = distance <= config.resetPoint && !isFingerDown && state.mode != .refreshing 250 | return 251 | } 252 | guard distance > 0, showRefreshControls else { 253 | isRefresherVisible = false 254 | return 255 | } 256 | 257 | isRefresherVisible = true 258 | 259 | if distance >= config.refreshAt, !renderLock { 260 | #if !os(visionOS) 261 | UIImpactFeedbackGenerator(style: .medium).impactOccurred() 262 | #endif 263 | renderLock = true 264 | canRefresh = false 265 | set(mode: .refreshing) 266 | 267 | refreshAction { 268 | // The ordering here is important - calling `set` on the main queue after `refreshAction` prevents 269 | // strange animaton behaviors on some complex views 270 | DispatchQueue.main.asyncAfter(deadline: .now() + config.holdTime) { 271 | set(mode: .notRefreshing) 272 | self.renderLock = false 273 | 274 | DispatchQueue.main.asyncAfter(deadline: .now() + config.cooldown) { 275 | self.canRefresh = !isFingerDown 276 | self.isRefresherVisible = false 277 | } 278 | } 279 | } 280 | 281 | } else if distance > 0, state.mode != .refreshing { 282 | set(mode: .pulling) 283 | } 284 | } 285 | 286 | func set(mode: RefreshMode) { 287 | state.mode = mode 288 | withAnimation { 289 | state.modeAnimated = mode 290 | } 291 | } 292 | } 293 | -------------------------------------------------------------------------------- /Sources/Refresher/ScrollView+Extensions.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | import SwiftUI 3 | 4 | extension ScrollView { 5 | public func refresher(style: Style = .default, 6 | config: Config = Config(), 7 | refreshView: @escaping (Binding) -> RefreshView, 8 | action: @escaping RefreshAction) -> RefreshableScrollView { 9 | RefreshableScrollView(axes: axes, 10 | showsIndicators: showsIndicators, 11 | refreshAction: action, 12 | style: style, 13 | config: config, 14 | refreshView: refreshView, 15 | content: content) 16 | } 17 | } 18 | 19 | extension ScrollView { 20 | public func refresher(style: Style = .default, 21 | config: Config = Config(), 22 | action: @escaping RefreshAction) -> some View { 23 | RefreshableScrollView(axes: axes, 24 | showsIndicators: showsIndicators, 25 | refreshAction: action, 26 | style: style, 27 | config: config, 28 | refreshView: DefaultRefreshView.init, 29 | content: content) 30 | } 31 | } 32 | 33 | 34 | extension ScrollView { 35 | public func refresher(style: Style = .default, 36 | config: Config = Config(), 37 | refreshView: @escaping (Binding) -> RefreshView, 38 | action: @escaping AsyncRefreshAction) -> RefreshableScrollView { 39 | RefreshableScrollView(axes: axes, 40 | showsIndicators: showsIndicators, 41 | refreshAction: { done in 42 | Task { @MainActor in 43 | await action() 44 | done() 45 | } 46 | }, 47 | style: style, 48 | config: config, 49 | refreshView: refreshView, 50 | content: content) 51 | } 52 | } 53 | 54 | extension ScrollView { 55 | public func refresher(style: Style = .default, 56 | config: Config = Config(), 57 | action: @escaping AsyncRefreshAction) -> some View { 58 | RefreshableScrollView(axes: axes, 59 | showsIndicators: showsIndicators, 60 | refreshAction: { done in 61 | Task { @MainActor in 62 | await action() 63 | done() 64 | } 65 | }, 66 | style: style, 67 | config: config, 68 | refreshView: DefaultRefreshView.init, 69 | content: content) 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /images/1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gh123man/SwiftUI-Refresher/5a24079e69e5ca62974ea0dbf4d8ef13ceedaad3/images/1.gif -------------------------------------------------------------------------------- /images/2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gh123man/SwiftUI-Refresher/5a24079e69e5ca62974ea0dbf4d8ef13ceedaad3/images/2.gif -------------------------------------------------------------------------------- /images/3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gh123man/SwiftUI-Refresher/5a24079e69e5ca62974ea0dbf4d8ef13ceedaad3/images/3.gif -------------------------------------------------------------------------------- /images/4.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gh123man/SwiftUI-Refresher/5a24079e69e5ca62974ea0dbf4d8ef13ceedaad3/images/4.gif -------------------------------------------------------------------------------- /images/5.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gh123man/SwiftUI-Refresher/5a24079e69e5ca62974ea0dbf4d8ef13ceedaad3/images/5.gif --------------------------------------------------------------------------------