0

The background of List is moving when keyboard appears. I have next implementation:

import SwiftUI

struct ListScroll: View {
    
    // Test data
    let data = [
        User(id: UUID(), name: "Yevhen", age: 35),
        User(id: UUID(), name: "Petro", age: 55),
        User(id: UUID(), name: "Djohn", age: 22),
        User(id: UUID(), name: "sad", age: 22),
        User(id: UUID(), name: "Asd", age: 22),
        User(id: UUID(), name: "Asdd", age: 22),
        User(id: UUID(), name: "Asd", age: 22),
        User(id: UUID(), name: "dasds", age: 22),
        User(id: UUID(), name: "asds", age: 22),
        User(id: UUID(), name: "das", age: 22),
        User(id: UUID(), name: "dsa", age: 22),
        User(id: UUID(), name: "das", age: 22),
        User(id: UUID(), name: "fdkn", age: 22),
        User(id: UUID(), name: "dsjn", age: 22),
        User(id: UUID(), name: "ddsasd", age: 22),
        User(id: UUID(), name: "asass", age: 22),
        User(id: UUID(), name: "ASD", age: 22),
        User(id: UUID(), name: "ASDS", age: 22),
        
        User(id: UUID(), name: "ASDS", age: 22),
        User(id: UUID(), name: "ASDS", age: 22),
        User(id: UUID(), name: "ASDS", age: 22),
        User(id: UUID(), name: "ASDS", age: 22),
        User(id: UUID(), name: "ASDS", age: 22),
        User(id: UUID(), name: "ASDS", age: 22),
    ]
    
    @State var text = "Testing text"
    
    @FocusState var focusedTask: User.ID?
    
    var body: some View {
        
        ZStack {
            Rectangle() // moves with keyaboard  
                .fill(.linearGradient(.init(colors: [.red, .blue, .orange]), startPoint: .topLeading, endPoint: .bottomTrailing))
                .ignoresSafeArea(.all)
            
            ScrollViewReader { scrollReader in
                List(data, id: \.self.id) { user in
                    VStack {
                        TextField("", text: $text )
                            .textFieldStyle(.roundedBorder)
                            .listRowSeparator(.hidden)
                            .listRowBackground(Color.clear)
                            .focused($focusedTask, equals: user.id)
                    }
                    
                }
                .scrollDismissesKeyboard(.immediately)
                .scrollContentBackground(.hidden)
            }
        }    
    }
}

struct ListScroll_Previews: PreviewProvider {
    static var previews: some View {
        ListScroll()
    }
}

The problem is that when TextField is in focus the keyboard moves Rectangle background regardless that it has .ignoresSafeArea(.all) modifier. It can be visible when the keyboard is hiding:

Screen present issue

When the keyboard hided the part of the background jump back to origin position:

Screen without issue

I tried to add .ignoresSafeArea(.keyboard) modifier on List. It resolve the issue but @FocuseState not working with this modifier.

Video demo: dropbox link

  • I could not detect any problem. Look fine. Are you using third party library for keyboard? Could you share screen recording what you have problem? – EsatGozcu Aug 17 '23 at 20:39
  • Hi @EsatGozcu, I do not have third party libraries. Here is [link](https://www.dropbox.com/scl/fi/vvm3elccoexdnxtx9x1qj/Screen-Recording-2023-08-17-at-18.59.16.mov?rlkey=iejuh9qwa3b32ae5l9yo6gfvp&dl=0) to the demo Which iOS version did you test? – Yevgen Sukhomud Aug 18 '23 at 09:17

1 Answers1

0

Are you using the latest beta iOS17 builds?

ScrollViewReader seems to be the culprit here. I tested on iOS17 beta 5 and 6, both deviated from expectations. Beta 4 works okay though. The latest 2 beta builds seem to have a bug, I suggest you file a bug report with Apple.

ayelvs
  • 425
  • 1
  • 5
  • 9