$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>SwiftUI - Make Grid row selectable including the text? - Stack Overflow|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin15PV0评论

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.)
Post a comment

comment list (0)

  1. No comments so far