title: SwiftUI in iOS14 Keyboard Avoidance Issues and IgnoresSafeArea Modifier Issues
body: <p>iOS13 saw TextField not having any sort of keyboard avoidance handling in place. As such, we created our how keyboard avoidance mechanism which works well. We upgraded to iOS14 and this resulted in TextFields having keyboard avoidance built in. However, the keyboard avoidance does not seem to work as expected.</p>
  <p><strong>Issue 1</strong>
  The first issue we experienced was keyboard avoidance not working expected for TextFields in and around the centre of the screen. Given this code:</p>
  <pre><code>struct ContentView: View {
      
      @State var text:String = &quot;&quot;
      
      var body: some View {
          
          TextField(&quot;Testing&quot;, text: $text)
  
      }
  }
  </code></pre>
  <p>On an and iPhone 8 Plus the Textfield is moved up. In our opinion this shouldn't be happening as the TextField will not be hidden by the keyboard and as such it should remain in the same place.</p>
  <p><strong>Question 1:</strong>
  Is this a bug and should it be reported to Apple? We believe this to be a bug / issue.</p>
  <p>We have found that using the following:</p>
  <pre><code>struct ContentView: View {
      
      @State var text:String = &quot;&quot;
      
      var body: some View {
          
          VStack {
              Spacer()
              TextField(&quot;Testing&quot;, text: $text)
          }
          
      }
  }
  </code></pre>
  <p>The TextField will be moved just above the keyboard. Which is the expected behaviour. We've also found that with the code below:</p>
  <pre><code>struct ContentView: View {
      
      @State var text:String = &quot;&quot;
      
      var body: some View {
          
          VStack {
              TextField(&quot;Testing&quot;, text: $text)
              Spacer()
          }
          
      }
  }
  </code></pre>
  <p>The TextField is not moved as it would never be covered by the TextField. Once again, this is the behaviour we expect. However, any TextField in and around the centre of the screen it would seem that the keyboard avoidance moves the TextField in scenario's where it shouldn't.</p>
  <p><strong>Issue 2</strong>
  Our app holds TextFields in and around the centre on certain screens and as such the issue discovered above simply adds to a poor user experience and so we looked to &quot;switch off&quot; this keyboard avoidance provided to us. We looked to use the <code>ignoresSafeArea</code> modifier as follows:</p>
  <pre><code>struct ContentView: View {
      
      @State var text:String = &quot;&quot;
      
      var body: some View {
  
          if #available(iOS 14.0, *) {
              
              VStack {
                  TextField(&quot;Testing&quot;, text: $text)
              }
              .ignoresSafeArea(.keyboard, edges: .bottom)
  
              
          } else {
              // Fallback on earlier versions
              // Our iOS13 Code
          }
                  
      }
  }
  </code></pre>
  <p>The observed result is that the modifier simply doesn't work. The TextField is still moved upwards. However when using something like this:</p>
  <pre><code>struct ContentView: View {
      
      @State var text:String = &quot;&quot;
      
      var body: some View {
  
          if #available(iOS 14.0, *) {
              
              VStack {
                  Spacer()
                  TextField(&quot;Testing&quot;, text: $text)
              }
              .ignoresSafeArea(.keyboard, edges: .bottom)
  
              
          } else {
              // Fallback on earlier versions
              // Our iOS13 Code
          }
                  
      }
  }
  </code></pre>
  <p>the <code>ignoresSafeArea</code> works and so this leads to the second question:</p>
  <p><strong>Question 2</strong>
  Is there are bug with the <code>ignoresSafeArea</code> modifier as well? Is this something that should be reported?</p>
  <p>It would seem that there is an underlying issue with TextFields in and around the centre of the screen?</p>
  <p><strong>Question 3</strong>
  Anyone know of ways around these issues? Because right now it's a huge problem on iOS14. The keyboard avoidance doesn't work and any attempt to try and switch it off doesn't work either.</p>
  <p>We are using Xcode 12.0 (12A7209)</p>
  <p><strong>Update</strong></p>
  <p>We have found that wrapping the TextField in a Geometry Reader that this seems to &quot;switch off&quot; Keyboard Avoidance for a TextField. However, we believe this to be a delightful hack that fixes the problem in one way but then also exposes that Keyboard Avoidance doesn't work in Geometry readers which could be a bug / issue for other people...</p>
  <pre><code>struct ContentView: View {
      
      @State var text:String = &quot;&quot;
      
      var body: some View {
  
          if #available(iOS 14.0, *) {
              
              GeometryReader { _ in
                  VStack {
                      Spacer().frame(height:500) //Compensate for other Views in the Stack
                      TextField(&quot;Testing&quot;, text: $text)
                  }
              }
              
          } else {
              // Fallback on earlier versions
              // Our iOS13 Code
          }
                  
      }
  }
  </code></pre>