siteline / swiftui-introspect

Introspect underlying UIKit/AppKit components from SwiftUI
MIT License
5.67k stars 351 forks source link

It's not working on List #110

Closed HolyPaPa99 closed 1 year ago

HolyPaPa99 commented 3 years ago
import Introspect
import SwiftUI

struct ListIntrospectorTest: View {
    var body: some View {
        List {
            Text("Item 1")
            Text("Item 2")
        }
        .introspectTableView { tableView in
            tableView.separatorStyle = .none
        }
        .introspectTableViewCell { cell in
            let backgroundView = UIView()
            backgroundView.backgroundColor = .clear
            cell.selectedBackgroundView = backgroundView
        }
    }
}

struct ListIntrospectorTest_Previews: PreviewProvider {
    static var previews: some View {
        ListIntrospectorTest()
    }
}

截屏2021-04-21 上午12 28 02

saparfriday commented 3 years ago

Same, it's not work(

JeremPlln commented 3 years ago

I have the same issue as described above. Any updates?

SplittyDev commented 3 years ago

Hi, sorry for the late reply, we didn't have much time in the past few weeks. Could you try using .introspectTableView inside of the List? We're still looking into weird edge cases where our discovery methods don't do a good job at finding the target component.

JeremPlln commented 3 years ago

I did try to use . introspectTableView inside of the List but the result is the same. However, I can change the .backgroundColor property but other properties such as .separatorStyle or .separatorInset are not working.

Plus, the changes added to UITableViewCell apply to visible cells only and are reset when cells go outside of the visible scope.

https://user-images.githubusercontent.com/8677849/119967053-43573180-bfac-11eb-91fd-9d06649625c2.mov https://user-images.githubusercontent.com/8677849/119966753-eb202f80-bfab-11eb-944a-5380d9253c2d.mov

HolyPaPa99 commented 3 years ago

Hi, guys. The SwiftUI 3.0 supports more features for List, including listRowSeparator modifier. wait for xcode 13 release or use xcode 13 beta

SauravPahadia commented 2 years ago

Any update on this?

samnm commented 2 years ago

It appears this doesn't work on iOS 14 because iOS 14 doesn't use a table view for Lists. iOS 15 and iOS 13 both do use tableviews I believe.

elai950 commented 2 years ago

Is there any progress about this bug?

 the changes added to UITableViewCell apply to visible cells only and are reset when cells go outside of the visible scope.
davdroman commented 1 year ago

A little late to this, but the new SwiftUIIntrospect module's API accounts for differences between OSes:

import SwiftUI
import SwiftUIIntrospect

struct ContentView: View {
    var body: some View {
        List {
            Text("Item")
                .introspect(.listCell, on: .iOS(.v13, .v14, .v15)) { tableViewCell in
                    print(type(of: tableViewCell)) // UITableViewCell
                }
                .introspect(.listCell, on: .iOS(.v16, .v17)) { collectionViewCell in
                    print(type(of: collectionViewCell)) // UICollectionViewCell
                }
        }
        .introspect(.list, on: .iOS(.v13, .v14, .v15)) { tableView in
            print(type(of: tableView)) // UITableView
        }
        .introspect(.list, on: .iOS(.v16, .v17)) { collectionView in
            print(type(of: collectionView)) // UICollectionView
        }
    }
}

Closing, but feel free to ask any follow up questions.