Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Difference in behavior between iOS 13 and 14 #8

Open
avi-screenovate opened this issue Feb 3, 2021 · 3 comments
Open

Difference in behavior between iOS 13 and 14 #8

avi-screenovate opened this issue Feb 3, 2021 · 3 comments

Comments

@avi-screenovate
Copy link

avi-screenovate commented Feb 3, 2021

Screen Shot 2021-02-03 at 9 48 47

The screenshot shows two simulators for iPhone 8: one running iOS 13.7 and the other 14.4. The code is identical between them, run from Xcode directly. I have verified the same behavior on a physical iOS 14 device.

In case it matters, the text field is actually hidden, and is in a ZStack with the button on the bottom, to make sure it forces the button to move up above the keyboard. During normal operation, the keyboard is never hidden, though of course we can do so in the simulator.

@avi-screenovate
Copy link
Author

avi-screenovate commented Feb 3, 2021

For anyone that needs this: I figured out that iOS 14 automatically changes the size of a VStack for the keyboard, making this modifier unnecessary.

I made the following change to KeyboardAdaptive.body(content:):

    func body(content: Content) -> some View {
        GeometryReader { (geometry) -> AnyView in
            if #available(iOS 14, *) {
                return AnyView(content)
            }

            return AnyView(content
                            .padding(.bottom, self.bottomPadding)
                            .onReceive(Publishers.keyboardHeight) { keyboardHeight in
                                let keyboardTop = geometry.frame(in: .global).height - keyboardHeight
                                let focusedTextInputBottom = UIResponder.currentFirstResponder?.globalFrame?.maxY ?? 0
                                self.bottomPadding = max(0, focusedTextInputBottom - keyboardTop - geometry.safeAreaInsets.bottom)
                            }
                            .animation(.easeOut(duration: 0.16))
            )
        }
    }

@ben-p-commits
Copy link

Update for iOS 15:

content
      .padding(.bottom, self.bottomPadding)
      .onReceive(Publishers.keyboardHeight) { keyboardHeight in
          let keyboardTop = geometry.frame(in: .global).height - min(0, keyboardHeight) // putting a floor on negative keyboard hight fixes a similar issue on iOS 15
          let focusedTextInputBottom = UIResponder.currentFirstResponder?.globalFrame?.maxY ?? 0
          self.bottomPadding = max(0, focusedTextInputBottom - keyboardTop)
  }
  .animation(.easeOut(duration: 0.25))

@Adarsh0Ranjan
Copy link

view is getting scrolled bit more..if the view is complex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants