Skip to content

Conversation

ivanmkc
Copy link

@ivanmkc ivanmkc commented Nov 16, 2020

Thanks for creating this Nick. I had a use case which required a slight modification that I thought might be useful for others.

Let's say we have this:

struct TestView: View {
    
    @State var text: String = ""
    
    var body: some View {
        VStack(spacing: 0) {
            Color.blue.frame(height: 300)
            
            Color.red
            
            TextField("Type something", text: $text)
                .frame(height: 100)
                .foregroundColor(Color.white)
                .background(Color.black)
        }
        .keyboardObserving()
    }
}

Using the current KeyboardObserving, the result looks like this:
before

You can see it modifies the relative sizes of Blue and Red since Blue is constrained while Red is not.

When I wrote my own keyboard avoiders before SwiftUI, I found messing with the frames sometimes gave hard to debug results so I had always preferred to simply use a transformation on the underlying layer and translate everything up.

This gives the following result:

after

It may not be what your extension intends but thought it was a nice option to have.

@ivanmkc ivanmkc changed the title [WIP] Switched from modifying frame to using an offset [Alternative method of modifying views] Switched from modifying frame to using an offset Nov 16, 2020
@ivanmkc ivanmkc force-pushed the fix/imkc--replace-frame-adjustment-with-offset branch from 5895ece to 2647c5d Compare November 16, 2020 11:44
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

Successfully merging this pull request may close these issues.

2 participants