├── .gitignore ├── KeyboardAvoidanceSwiftUI.xcodeproj ├── project.pbxproj └── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ └── IDEWorkspaceChecks.plist ├── KeyboardAvoidanceSwiftUI ├── App │ ├── AppDelegate.swift │ └── SceneDelegate.swift ├── ContentView.swift ├── KeyboardAdaptive.swift ├── KeyboardHeightPublisher.swift ├── SupportingFiles │ ├── Assets.xcassets │ │ ├── AppIcon.appiconset │ │ │ └── Contents.json │ │ └── Contents.json │ ├── Base.lproj │ │ └── LaunchScreen.storyboard │ └── Info.plist └── UIResponder+Current.swift ├── LICENSE ├── README.md └── demo.gif /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## User settings 6 | xcuserdata/ 7 | 8 | ## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) 9 | *.xcscmblueprint 10 | *.xccheckout 11 | 12 | ## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) 13 | build/ 14 | DerivedData/ 15 | *.moved-aside 16 | *.pbxuser 17 | !default.pbxuser 18 | *.mode1v3 19 | !default.mode1v3 20 | *.mode2v3 21 | !default.mode2v3 22 | *.perspectivev3 23 | !default.perspectivev3 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | 28 | ## App packaging 29 | *.ipa 30 | *.dSYM.zip 31 | *.dSYM 32 | 33 | ## Playgrounds 34 | timeline.xctimeline 35 | playground.xcworkspace 36 | 37 | # Swift Package Manager 38 | # 39 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 40 | # Packages/ 41 | # Package.pins 42 | # Package.resolved 43 | # *.xcodeproj 44 | # 45 | # Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata 46 | # hence it is not needed unless you have added a package configuration file to your project 47 | # .swiftpm 48 | 49 | .build/ 50 | 51 | # CocoaPods 52 | # 53 | # We recommend against adding the Pods directory to your .gitignore. However 54 | # you should judge for yourself, the pros and cons are mentioned at: 55 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 56 | # 57 | # Pods/ 58 | # 59 | # Add this line if you want to avoid checking in source code from the Xcode workspace 60 | # *.xcworkspace 61 | 62 | # Carthage 63 | # 64 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 65 | # Carthage/Checkouts 66 | 67 | Carthage/Build/ 68 | 69 | # Accio dependency management 70 | Dependencies/ 71 | .accio/ 72 | 73 | # fastlane 74 | # 75 | # It is recommended to not store the screenshots in the git repo. 76 | # Instead, use fastlane to re-generate the screenshots whenever they are needed. 77 | # For more information about the recommended setup visit: 78 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 79 | 80 | fastlane/report.xml 81 | fastlane/Preview.html 82 | fastlane/screenshots/**/*.png 83 | fastlane/test_output 84 | 85 | # Code Injection 86 | # 87 | # After new code Injection tools there's a generated folder /iOSInjectionProject 88 | # https://github.com/johnno1962/injectionforxcode 89 | 90 | iOSInjectionProject/ 91 | -------------------------------------------------------------------------------- /KeyboardAvoidanceSwiftUI.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 889E799C242E4B6800375EA4 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 889E799B242E4B6800375EA4 /* AppDelegate.swift */; }; 11 | 889E799E242E4B6800375EA4 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 889E799D242E4B6800375EA4 /* SceneDelegate.swift */; }; 12 | 889E79A0242E4B6800375EA4 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 889E799F242E4B6800375EA4 /* ContentView.swift */; }; 13 | 889E79A2242E4B6A00375EA4 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 889E79A1242E4B6A00375EA4 /* Assets.xcassets */; }; 14 | 889E79A8242E4B6A00375EA4 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 889E79A6242E4B6A00375EA4 /* LaunchScreen.storyboard */; }; 15 | 889E79B0242E4CF200375EA4 /* KeyboardHeightPublisher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 889E79AF242E4CF200375EA4 /* KeyboardHeightPublisher.swift */; }; 16 | 889E79B2242E4D0F00375EA4 /* UIResponder+Current.swift in Sources */ = {isa = PBXBuildFile; fileRef = 889E79B1242E4D0F00375EA4 /* UIResponder+Current.swift */; }; 17 | 889E79B4242E4E3D00375EA4 /* KeyboardAdaptive.swift in Sources */ = {isa = PBXBuildFile; fileRef = 889E79B3242E4E3D00375EA4 /* KeyboardAdaptive.swift */; }; 18 | /* End PBXBuildFile section */ 19 | 20 | /* Begin PBXFileReference section */ 21 | 889E7998242E4B6800375EA4 /* KeyboardAvoidanceSwiftUI.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = KeyboardAvoidanceSwiftUI.app; sourceTree = BUILT_PRODUCTS_DIR; }; 22 | 889E799B242E4B6800375EA4 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 23 | 889E799D242E4B6800375EA4 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; 24 | 889E799F242E4B6800375EA4 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 25 | 889E79A1242E4B6A00375EA4 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 26 | 889E79A7242E4B6A00375EA4 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 27 | 889E79A9242E4B6A00375EA4 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 28 | 889E79AF242E4CF200375EA4 /* KeyboardHeightPublisher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyboardHeightPublisher.swift; sourceTree = ""; }; 29 | 889E79B1242E4D0F00375EA4 /* UIResponder+Current.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIResponder+Current.swift"; sourceTree = ""; }; 30 | 889E79B3242E4E3D00375EA4 /* KeyboardAdaptive.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyboardAdaptive.swift; sourceTree = ""; }; 31 | /* End PBXFileReference section */ 32 | 33 | /* Begin PBXFrameworksBuildPhase section */ 34 | 889E7995242E4B6800375EA4 /* Frameworks */ = { 35 | isa = PBXFrameworksBuildPhase; 36 | buildActionMask = 2147483647; 37 | files = ( 38 | ); 39 | runOnlyForDeploymentPostprocessing = 0; 40 | }; 41 | /* End PBXFrameworksBuildPhase section */ 42 | 43 | /* Begin PBXGroup section */ 44 | 889E798F242E4B6800375EA4 = { 45 | isa = PBXGroup; 46 | children = ( 47 | 889E799A242E4B6800375EA4 /* KeyboardAvoidanceSwiftUI */, 48 | 889E7999242E4B6800375EA4 /* Products */, 49 | ); 50 | sourceTree = ""; 51 | }; 52 | 889E7999242E4B6800375EA4 /* Products */ = { 53 | isa = PBXGroup; 54 | children = ( 55 | 889E7998242E4B6800375EA4 /* KeyboardAvoidanceSwiftUI.app */, 56 | ); 57 | name = Products; 58 | sourceTree = ""; 59 | }; 60 | 889E799A242E4B6800375EA4 /* KeyboardAvoidanceSwiftUI */ = { 61 | isa = PBXGroup; 62 | children = ( 63 | 889E79B5242E4E9C00375EA4 /* App */, 64 | 889E799F242E4B6800375EA4 /* ContentView.swift */, 65 | 889E79B3242E4E3D00375EA4 /* KeyboardAdaptive.swift */, 66 | 889E79AF242E4CF200375EA4 /* KeyboardHeightPublisher.swift */, 67 | 889E79B1242E4D0F00375EA4 /* UIResponder+Current.swift */, 68 | 889E79B6242E4EA900375EA4 /* SupportingFiles */, 69 | ); 70 | path = KeyboardAvoidanceSwiftUI; 71 | sourceTree = ""; 72 | }; 73 | 889E79B5242E4E9C00375EA4 /* App */ = { 74 | isa = PBXGroup; 75 | children = ( 76 | 889E799B242E4B6800375EA4 /* AppDelegate.swift */, 77 | 889E799D242E4B6800375EA4 /* SceneDelegate.swift */, 78 | ); 79 | path = App; 80 | sourceTree = ""; 81 | }; 82 | 889E79B6242E4EA900375EA4 /* SupportingFiles */ = { 83 | isa = PBXGroup; 84 | children = ( 85 | 889E79A1242E4B6A00375EA4 /* Assets.xcassets */, 86 | 889E79A6242E4B6A00375EA4 /* LaunchScreen.storyboard */, 87 | 889E79A9242E4B6A00375EA4 /* Info.plist */, 88 | ); 89 | path = SupportingFiles; 90 | sourceTree = ""; 91 | }; 92 | /* End PBXGroup section */ 93 | 94 | /* Begin PBXNativeTarget section */ 95 | 889E7997242E4B6800375EA4 /* KeyboardAvoidanceSwiftUI */ = { 96 | isa = PBXNativeTarget; 97 | buildConfigurationList = 889E79AC242E4B6A00375EA4 /* Build configuration list for PBXNativeTarget "KeyboardAvoidanceSwiftUI" */; 98 | buildPhases = ( 99 | 889E7994242E4B6800375EA4 /* Sources */, 100 | 889E7995242E4B6800375EA4 /* Frameworks */, 101 | 889E7996242E4B6800375EA4 /* Resources */, 102 | ); 103 | buildRules = ( 104 | ); 105 | dependencies = ( 106 | ); 107 | name = KeyboardAvoidanceSwiftUI; 108 | productName = KeyboardAvoidanceSwiftUI; 109 | productReference = 889E7998242E4B6800375EA4 /* KeyboardAvoidanceSwiftUI.app */; 110 | productType = "com.apple.product-type.application"; 111 | }; 112 | /* End PBXNativeTarget section */ 113 | 114 | /* Begin PBXProject section */ 115 | 889E7990242E4B6800375EA4 /* Project object */ = { 116 | isa = PBXProject; 117 | attributes = { 118 | LastSwiftUpdateCheck = 1140; 119 | LastUpgradeCheck = 1140; 120 | ORGANIZATIONNAME = "Vadim Bulavin"; 121 | TargetAttributes = { 122 | 889E7997242E4B6800375EA4 = { 123 | CreatedOnToolsVersion = 11.4; 124 | }; 125 | }; 126 | }; 127 | buildConfigurationList = 889E7993242E4B6800375EA4 /* Build configuration list for PBXProject "KeyboardAvoidanceSwiftUI" */; 128 | compatibilityVersion = "Xcode 9.3"; 129 | developmentRegion = en; 130 | hasScannedForEncodings = 0; 131 | knownRegions = ( 132 | en, 133 | Base, 134 | ); 135 | mainGroup = 889E798F242E4B6800375EA4; 136 | productRefGroup = 889E7999242E4B6800375EA4 /* Products */; 137 | projectDirPath = ""; 138 | projectRoot = ""; 139 | targets = ( 140 | 889E7997242E4B6800375EA4 /* KeyboardAvoidanceSwiftUI */, 141 | ); 142 | }; 143 | /* End PBXProject section */ 144 | 145 | /* Begin PBXResourcesBuildPhase section */ 146 | 889E7996242E4B6800375EA4 /* Resources */ = { 147 | isa = PBXResourcesBuildPhase; 148 | buildActionMask = 2147483647; 149 | files = ( 150 | 889E79A8242E4B6A00375EA4 /* LaunchScreen.storyboard in Resources */, 151 | 889E79A2242E4B6A00375EA4 /* Assets.xcassets in Resources */, 152 | ); 153 | runOnlyForDeploymentPostprocessing = 0; 154 | }; 155 | /* End PBXResourcesBuildPhase section */ 156 | 157 | /* Begin PBXSourcesBuildPhase section */ 158 | 889E7994242E4B6800375EA4 /* Sources */ = { 159 | isa = PBXSourcesBuildPhase; 160 | buildActionMask = 2147483647; 161 | files = ( 162 | 889E79B0242E4CF200375EA4 /* KeyboardHeightPublisher.swift in Sources */, 163 | 889E799C242E4B6800375EA4 /* AppDelegate.swift in Sources */, 164 | 889E79B4242E4E3D00375EA4 /* KeyboardAdaptive.swift in Sources */, 165 | 889E799E242E4B6800375EA4 /* SceneDelegate.swift in Sources */, 166 | 889E79B2242E4D0F00375EA4 /* UIResponder+Current.swift in Sources */, 167 | 889E79A0242E4B6800375EA4 /* ContentView.swift in Sources */, 168 | ); 169 | runOnlyForDeploymentPostprocessing = 0; 170 | }; 171 | /* End PBXSourcesBuildPhase section */ 172 | 173 | /* Begin PBXVariantGroup section */ 174 | 889E79A6242E4B6A00375EA4 /* LaunchScreen.storyboard */ = { 175 | isa = PBXVariantGroup; 176 | children = ( 177 | 889E79A7242E4B6A00375EA4 /* Base */, 178 | ); 179 | name = LaunchScreen.storyboard; 180 | sourceTree = ""; 181 | }; 182 | /* End PBXVariantGroup section */ 183 | 184 | /* Begin XCBuildConfiguration section */ 185 | 889E79AA242E4B6A00375EA4 /* Debug */ = { 186 | isa = XCBuildConfiguration; 187 | buildSettings = { 188 | ALWAYS_SEARCH_USER_PATHS = NO; 189 | CLANG_ANALYZER_NONNULL = YES; 190 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 191 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 192 | CLANG_CXX_LIBRARY = "libc++"; 193 | CLANG_ENABLE_MODULES = YES; 194 | CLANG_ENABLE_OBJC_ARC = YES; 195 | CLANG_ENABLE_OBJC_WEAK = YES; 196 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 197 | CLANG_WARN_BOOL_CONVERSION = YES; 198 | CLANG_WARN_COMMA = YES; 199 | CLANG_WARN_CONSTANT_CONVERSION = YES; 200 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 201 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 202 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 203 | CLANG_WARN_EMPTY_BODY = YES; 204 | CLANG_WARN_ENUM_CONVERSION = YES; 205 | CLANG_WARN_INFINITE_RECURSION = YES; 206 | CLANG_WARN_INT_CONVERSION = YES; 207 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 208 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 209 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 210 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 211 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 212 | CLANG_WARN_STRICT_PROTOTYPES = YES; 213 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 214 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 215 | CLANG_WARN_UNREACHABLE_CODE = YES; 216 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 217 | COPY_PHASE_STRIP = NO; 218 | DEBUG_INFORMATION_FORMAT = dwarf; 219 | ENABLE_STRICT_OBJC_MSGSEND = YES; 220 | ENABLE_TESTABILITY = YES; 221 | GCC_C_LANGUAGE_STANDARD = gnu11; 222 | GCC_DYNAMIC_NO_PIC = NO; 223 | GCC_NO_COMMON_BLOCKS = YES; 224 | GCC_OPTIMIZATION_LEVEL = 0; 225 | GCC_PREPROCESSOR_DEFINITIONS = ( 226 | "DEBUG=1", 227 | "$(inherited)", 228 | ); 229 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 230 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 231 | GCC_WARN_UNDECLARED_SELECTOR = YES; 232 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 233 | GCC_WARN_UNUSED_FUNCTION = YES; 234 | GCC_WARN_UNUSED_VARIABLE = YES; 235 | IPHONEOS_DEPLOYMENT_TARGET = 13.4; 236 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 237 | MTL_FAST_MATH = YES; 238 | ONLY_ACTIVE_ARCH = YES; 239 | SDKROOT = iphoneos; 240 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 241 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 242 | }; 243 | name = Debug; 244 | }; 245 | 889E79AB242E4B6A00375EA4 /* Release */ = { 246 | isa = XCBuildConfiguration; 247 | buildSettings = { 248 | ALWAYS_SEARCH_USER_PATHS = NO; 249 | CLANG_ANALYZER_NONNULL = YES; 250 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 251 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 252 | CLANG_CXX_LIBRARY = "libc++"; 253 | CLANG_ENABLE_MODULES = YES; 254 | CLANG_ENABLE_OBJC_ARC = YES; 255 | CLANG_ENABLE_OBJC_WEAK = YES; 256 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 257 | CLANG_WARN_BOOL_CONVERSION = YES; 258 | CLANG_WARN_COMMA = YES; 259 | CLANG_WARN_CONSTANT_CONVERSION = YES; 260 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 261 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 262 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 263 | CLANG_WARN_EMPTY_BODY = YES; 264 | CLANG_WARN_ENUM_CONVERSION = YES; 265 | CLANG_WARN_INFINITE_RECURSION = YES; 266 | CLANG_WARN_INT_CONVERSION = YES; 267 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 268 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 269 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 270 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 271 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 272 | CLANG_WARN_STRICT_PROTOTYPES = YES; 273 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 274 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 275 | CLANG_WARN_UNREACHABLE_CODE = YES; 276 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 277 | COPY_PHASE_STRIP = NO; 278 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 279 | ENABLE_NS_ASSERTIONS = NO; 280 | ENABLE_STRICT_OBJC_MSGSEND = YES; 281 | GCC_C_LANGUAGE_STANDARD = gnu11; 282 | GCC_NO_COMMON_BLOCKS = YES; 283 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 284 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 285 | GCC_WARN_UNDECLARED_SELECTOR = YES; 286 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 287 | GCC_WARN_UNUSED_FUNCTION = YES; 288 | GCC_WARN_UNUSED_VARIABLE = YES; 289 | IPHONEOS_DEPLOYMENT_TARGET = 13.4; 290 | MTL_ENABLE_DEBUG_INFO = NO; 291 | MTL_FAST_MATH = YES; 292 | SDKROOT = iphoneos; 293 | SWIFT_COMPILATION_MODE = wholemodule; 294 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 295 | VALIDATE_PRODUCT = YES; 296 | }; 297 | name = Release; 298 | }; 299 | 889E79AD242E4B6A00375EA4 /* Debug */ = { 300 | isa = XCBuildConfiguration; 301 | buildSettings = { 302 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 303 | CODE_SIGN_STYLE = Automatic; 304 | DEVELOPMENT_ASSET_PATHS = ""; 305 | ENABLE_PREVIEWS = YES; 306 | INFOPLIST_FILE = KeyboardAvoidanceSwiftUI/SupportingFiles/Info.plist; 307 | LD_RUNPATH_SEARCH_PATHS = ( 308 | "$(inherited)", 309 | "@executable_path/Frameworks", 310 | ); 311 | PRODUCT_BUNDLE_IDENTIFIER = vadimbulavin.KeyboardAvoidanceSwiftUI; 312 | PRODUCT_NAME = "$(TARGET_NAME)"; 313 | SWIFT_VERSION = 5.0; 314 | TARGETED_DEVICE_FAMILY = "1,2"; 315 | }; 316 | name = Debug; 317 | }; 318 | 889E79AE242E4B6A00375EA4 /* Release */ = { 319 | isa = XCBuildConfiguration; 320 | buildSettings = { 321 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 322 | CODE_SIGN_STYLE = Automatic; 323 | DEVELOPMENT_ASSET_PATHS = ""; 324 | ENABLE_PREVIEWS = YES; 325 | INFOPLIST_FILE = KeyboardAvoidanceSwiftUI/SupportingFiles/Info.plist; 326 | LD_RUNPATH_SEARCH_PATHS = ( 327 | "$(inherited)", 328 | "@executable_path/Frameworks", 329 | ); 330 | PRODUCT_BUNDLE_IDENTIFIER = vadimbulavin.KeyboardAvoidanceSwiftUI; 331 | PRODUCT_NAME = "$(TARGET_NAME)"; 332 | SWIFT_VERSION = 5.0; 333 | TARGETED_DEVICE_FAMILY = "1,2"; 334 | }; 335 | name = Release; 336 | }; 337 | /* End XCBuildConfiguration section */ 338 | 339 | /* Begin XCConfigurationList section */ 340 | 889E7993242E4B6800375EA4 /* Build configuration list for PBXProject "KeyboardAvoidanceSwiftUI" */ = { 341 | isa = XCConfigurationList; 342 | buildConfigurations = ( 343 | 889E79AA242E4B6A00375EA4 /* Debug */, 344 | 889E79AB242E4B6A00375EA4 /* Release */, 345 | ); 346 | defaultConfigurationIsVisible = 0; 347 | defaultConfigurationName = Release; 348 | }; 349 | 889E79AC242E4B6A00375EA4 /* Build configuration list for PBXNativeTarget "KeyboardAvoidanceSwiftUI" */ = { 350 | isa = XCConfigurationList; 351 | buildConfigurations = ( 352 | 889E79AD242E4B6A00375EA4 /* Debug */, 353 | 889E79AE242E4B6A00375EA4 /* Release */, 354 | ); 355 | defaultConfigurationIsVisible = 0; 356 | defaultConfigurationName = Release; 357 | }; 358 | /* End XCConfigurationList section */ 359 | }; 360 | rootObject = 889E7990242E4B6800375EA4 /* Project object */; 361 | } 362 | -------------------------------------------------------------------------------- /KeyboardAvoidanceSwiftUI.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /KeyboardAvoidanceSwiftUI.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /KeyboardAvoidanceSwiftUI/App/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // KeyboardAvoidanceSwiftUI 4 | // 5 | // Created by Vadim Bulavin on 3/27/20. 6 | // Copyright © 2020 Vadim Bulavin. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 15 | return true 16 | } 17 | 18 | func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { 19 | return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /KeyboardAvoidanceSwiftUI/App/SceneDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SceneDelegate.swift 3 | // KeyboardAvoidanceSwiftUI 4 | // 5 | // Created by Vadim Bulavin on 3/27/20. 6 | // Copyright © 2020 Vadim Bulavin. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import SwiftUI 11 | 12 | class SceneDelegate: UIResponder, UIWindowSceneDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { 17 | if let windowScene = scene as? UIWindowScene { 18 | let window = UIWindow(windowScene: windowScene) 19 | window.rootViewController = UIHostingController(rootView: ContentView()) 20 | self.window = window 21 | window.makeKeyAndVisible() 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /KeyboardAvoidanceSwiftUI/ContentView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ContentView.swift 3 | // KeyboardAvoidanceSwiftUI 4 | // 5 | // Created by Vadim Bulavin on 3/27/20. 6 | // Copyright © 2020 Vadim Bulavin. All rights reserved. 7 | // 8 | 9 | import SwiftUI 10 | import Combine 11 | import UIKit 12 | 13 | struct ContentView: View { 14 | var body: some View { 15 | TabView { 16 | OverlapDemo() 17 | .tabItem { Text("Overlap") } 18 | 19 | WithoutOverlapDemo() 20 | .tabItem { Text("No Overlap") } 21 | 22 | } 23 | } 24 | } 25 | 26 | struct OverlapDemo: View { 27 | @State private var text = "" 28 | 29 | var body: some View { 30 | VStack { 31 | Spacer() 32 | 33 | TextField("Enter something", text: $text) 34 | .textFieldStyle(RoundedBorderTextFieldStyle()) 35 | } 36 | .padding() 37 | .keyboardAdaptive() 38 | } 39 | } 40 | 41 | struct WithoutOverlapDemo: View { 42 | @State private var text = "" 43 | 44 | var body: some View { 45 | VStack { 46 | Spacer() 47 | 48 | TextField("Enter something", text: $text) 49 | .textFieldStyle(RoundedBorderTextFieldStyle()) 50 | 51 | Spacer() 52 | } 53 | .padding() 54 | .keyboardAdaptive() 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /KeyboardAvoidanceSwiftUI/KeyboardAdaptive.swift: -------------------------------------------------------------------------------- 1 | // 2 | // KeyboardAdaptive.swift 3 | // KeyboardAvoidanceSwiftUI 4 | // 5 | // Created by Vadim Bulavin on 3/27/20. 6 | // Copyright © 2020 Vadim Bulavin. All rights reserved. 7 | // 8 | 9 | import SwiftUI 10 | import Combine 11 | 12 | /// Note that the `KeyboardAdaptive` modifier wraps your view in a `GeometryReader`, 13 | /// which attempts to fill all the available space, potentially increasing content view size. 14 | struct KeyboardAdaptive: ViewModifier { 15 | @State private var bottomPadding: CGFloat = 0 16 | 17 | func body(content: Content) -> some View { 18 | GeometryReader { geometry in 19 | content 20 | .padding(.bottom, self.bottomPadding) 21 | .onReceive(Publishers.keyboardHeight) { keyboardHeight in 22 | let keyboardTop = geometry.frame(in: .global).height - keyboardHeight 23 | let focusedTextInputBottom = UIResponder.currentFirstResponder?.globalFrame?.maxY ?? 0 24 | self.bottomPadding = max(0, focusedTextInputBottom - keyboardTop - geometry.safeAreaInsets.bottom) 25 | } 26 | .animation(.easeOut(duration: 0.16)) 27 | } 28 | } 29 | } 30 | 31 | extension View { 32 | func keyboardAdaptive() -> some View { 33 | ModifiedContent(content: self, modifier: KeyboardAdaptive()) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /KeyboardAvoidanceSwiftUI/KeyboardHeightPublisher.swift: -------------------------------------------------------------------------------- 1 | // 2 | // KeyboardHeightPublisher.swift 3 | // KeyboardAvoidanceSwiftUI 4 | // 5 | // Created by Vadim Bulavin on 3/27/20. 6 | // Copyright © 2020 Vadim Bulavin. All rights reserved. 7 | // 8 | 9 | import Combine 10 | import UIKit 11 | 12 | extension Publishers { 13 | static var keyboardHeight: AnyPublisher { 14 | let willShow = NotificationCenter.default.publisher(for: UIApplication.keyboardWillShowNotification) 15 | .map { $0.keyboardHeight } 16 | 17 | let willHide = NotificationCenter.default.publisher(for: UIApplication.keyboardWillHideNotification) 18 | .map { _ in CGFloat(0) } 19 | 20 | return MergeMany(willShow, willHide) 21 | .eraseToAnyPublisher() 22 | } 23 | } 24 | 25 | extension Notification { 26 | var keyboardHeight: CGFloat { 27 | return (userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect)?.height ?? 0 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /KeyboardAvoidanceSwiftUI/SupportingFiles/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 | "info" : { 95 | "author" : "xcode", 96 | "version" : 1 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /KeyboardAvoidanceSwiftUI/SupportingFiles/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /KeyboardAvoidanceSwiftUI/SupportingFiles/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /KeyboardAvoidanceSwiftUI/SupportingFiles/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UIApplicationSceneManifest 24 | 25 | UIApplicationSupportsMultipleScenes 26 | 27 | UISceneConfigurations 28 | 29 | UIWindowSceneSessionRoleApplication 30 | 31 | 32 | UISceneConfigurationName 33 | Default Configuration 34 | UISceneDelegateClassName 35 | $(PRODUCT_MODULE_NAME).SceneDelegate 36 | 37 | 38 | 39 | 40 | UILaunchStoryboardName 41 | LaunchScreen 42 | UIRequiredDeviceCapabilities 43 | 44 | armv7 45 | 46 | UISupportedInterfaceOrientations 47 | 48 | UIInterfaceOrientationPortrait 49 | UIInterfaceOrientationLandscapeLeft 50 | UIInterfaceOrientationLandscapeRight 51 | 52 | UISupportedInterfaceOrientations~ipad 53 | 54 | UIInterfaceOrientationPortrait 55 | UIInterfaceOrientationPortraitUpsideDown 56 | UIInterfaceOrientationLandscapeLeft 57 | UIInterfaceOrientationLandscapeRight 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /KeyboardAvoidanceSwiftUI/UIResponder+Current.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIResponder+Current.swift 3 | // KeyboardAvoidanceSwiftUI 4 | // 5 | // Created by Vadim Bulavin on 3/27/20. 6 | // Copyright © 2020 Vadim Bulavin. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import UIKit 11 | 12 | // From https://stackoverflow.com/a/14135456/6870041 13 | extension UIResponder { 14 | static var currentFirstResponder: UIResponder? { 15 | _currentFirstResponder = nil 16 | UIApplication.shared.sendAction(#selector(UIResponder.findFirstResponder(_:)), to: nil, from: nil, for: nil) 17 | return _currentFirstResponder 18 | } 19 | 20 | private static weak var _currentFirstResponder: UIResponder? 21 | 22 | @objc private func findFirstResponder(_ sender: Any) { 23 | UIResponder._currentFirstResponder = self 24 | } 25 | 26 | var globalFrame: CGRect? { 27 | guard let view = self as? UIView else { return nil } 28 | return view.superview?.convert(view.frame, to: nil) 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Article related to this project 2 | 3 | - [Keyboard Avoidance for SwiftUI Views](https://www.vadimbulavin.com/how-to-move-swiftui-view-when-keyboard-covers-text-field/). 4 | 5 | --- 6 | 7 | # KeyboardAvoidanceSwiftUI 8 | 9 | A sample project showing how to move SwiftUI view up when keyboard covers a text field. 10 | 11 | Usage: 12 | 13 | ```swift 14 | struct ContentView: View { 15 | @State private var text = "" 16 | 17 | var body: some View { 18 | VStack { 19 | Spacer() 20 | 21 | TextField("Enter something", text: $text) 22 | .textFieldStyle(RoundedBorderTextFieldStyle()) 23 | } 24 | .padding() 25 | .keyboardAdaptive() // <--- Apply the view modifier 26 | } 27 | } 28 | ```` 29 | 30 | Result: 31 | 32 |

33 | How to manage the iOS system keyboard when it covers a SwiftUI text field 34 |

35 | -------------------------------------------------------------------------------- /demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/V8tr/KeyboardAvoidanceSwiftUI/5479f207f0404f604d1fdba6bf0ab32eae8cea23/demo.gif --------------------------------------------------------------------------------