0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

SwiftUIで横スクロールのフィルタチップを作るときに気をつけた3つのこと

0
Posted at

ゲームの配置図(レイアウト)をレベル別に絞り込む個人アプリで、横スクロールのフィルタチップを実装しました。そのときにハマった点をまとめます。

1. 選択中のチップを自動で画面内に表示する

ScrollViewReader と proxy.scrollTo(id, anchor: .center) を使い、選択が変わったら onChange でスクロールさせます。初期表示時は onAppear でも呼ぶ必要があります。

2. タップ領域を広げる

チップの見た目は小さくても、.contentShape(Capsule()) と十分な padding でタップしやすくしました。誤タップがかなり減りました。

3. 状態は1か所にまとめる

選択値は親ビューの @State に置き、チップには Binding で渡すだけにしました。一覧のフィルタとチップの表示がずれる問題がなくなりました。

小さな部品ですが、毎回触る場所なので使い心地に大きく影響しました。もっと良い書き方があればコメントで教えてください。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?