SwiftUI - Make Grid row selectable including the text? - Stack Overflow

In a grid View, here a LazyVGrid, I understand that to make a row "tappable" one should add t

In a grid View, here a LazyVGrid, I understand that to make a row "tappable" one should add the .contentShape() modifier with a Rectangle() shape:

LazyVGrid(columns: [GridItem(.flexible()), GridItem(.flexible())]) {
    Text("first column")
    Text("second column")
    // potentially many columns
}
//.overlay(content: { Rectangle().fill() })
.contentShape(Rectangle())
.onTapGesture {
    print("row tapped")
}

However, while the space in the row is now tappable, clicking on the text is not recognized as a tap. The text is selectable for copying because I have .textSelection(.enabled) on its container.

Is there a way to make the text tappable as well?

And can that be achieved while allowing it to still be selectable?

  • I have found that using an overlay with a filled Rectangle works, but not if the fill is Color.clear.
  • I saw an idea to fill with UIColor of System background, but I would rather not import UIKit.
  • I saw the idea of using a fill with opacity so little that it was not apparent to the user. Is that really the only way to do it? (Also the text is no longer selectable.)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745673742a4639560.html

相关推荐

  • SwiftUI - Make Grid row selectable including the text? - Stack Overflow

    In a grid View, here a LazyVGrid, I understand that to make a row "tappable" one should add t

    5小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信