Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Jetpack Compose drag gesture and pinch gesture
Search
Moyuru Aizawa
April 21, 2023
Programming
4.3k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Jetpack Compose drag gesture and pinch gesture
Moyuru Aizawa
April 21, 2023
More Decks by Moyuru Aizawa
See All by Moyuru Aizawa
BLUETOOTH_SCAN and iBeacon
lvla
1
150
graphicsLayer
lvla
0
290
BluetoothDevice.getName()に裏切られた話
lvla
0
410
Jetpack Composeで画像クロップ機能を実装する
lvla
0
1.3k
Jetpack Compose Layout API
lvla
1
710
BLEを使ったアプリを継続的に開発するために
lvla
0
1.1k
RecyclerView.ItemAnimator
lvla
1
380
RecycledViewPool
lvla
1
290
CameraX
lvla
2
2.5k
Other Decks in Programming
See All in Programming
言語を使う側から、作る側へ。 自作 Lisp で得た新たな気づき。
andpad
0
110
【やさしく解説 設計編・中級 #6】良いアーキテクチャとは ~ 一本の登り道の、行き先 ~
panda728
PRO
0
130
OSINT for SRE: 学術論文とポストモーテムから探る システム障害の共通パターン / SRE NEXT 2026
tomoyk
1
3.4k
【やさしく解説 設計編 #1】「ドメイン駆動」と「実装駆動」ってなに? 〜設計の考え方を、たとえ話で学ぼう〜
panda728
PRO
1
110
どこまでゆるくて許されるのか
tk3fftk
0
470
『コードを書く以外の』エンジニアリング〜課金基盤移行プロジェクト推進のためのTips4選
yuriko1211
0
300
ランチタイムLT会3周年!ランチタイムLT会を3年間続けられたお話
y0hgi
1
140
act2-costs.pdf
sumedhbala
0
110
Vue × Nuxt × Oxc どこまで使える?実運用の現在地
andpad
0
370
Webフレームワークの ベンチマークについて
yusukebe
0
200
えっ!!コードを読まずに開発を!?
hananouchi
0
190
継続モナドとリアクティブプログラミング
yukikurage
3
490
Featured
See All Featured
Unsuck your backbone
ammeep
672
58k
Utilizing Notion as your number one productivity tool
mfonobong
4
380
WCS-LA-2024
lcolladotor
0
680
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
490
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
610
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
870
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
sira's awesome portfolio website redesign presentation
elsirapls
0
300
So, you think you're a good person
axbom
PRO
2
2.1k
Accessibility Awareness
sabderemane
1
150
Large-scale JavaScript Application Architecture
addyosmani
515
110k
The Limits of Empathy - UXLibs8
cassininazir
1
440
Transcript
Jetpack Compose Drag Gesture / Pinch Gesture @MoyuruAizawa
Moyuru Aizawa Software Engineer of Catlog, RABO. Previously at Azit,
CyberAgent, and Eureka. Love Metal, Hardcore and EDM. MoyuruAizawa
github.com/MoyuruAizawa/Cropify
࠷ۙࣄͰ Drag Gestureͱ͔Pinch Gestureͱ͔ ѻͬͨͷͰͦͷհ
CatlogͬͯԿ? Catlog Catlog Board ŮŧŠźƃɺͪΌΜͱ͏Μͨ͜͠?͓ͬͨ͜͠͠? සͩͬͨΓ͠ͳ͍? ମॏͷٸܹͳ૿ݮͱ͔ͯ͠ͳ͍? ͬͯͷ͕͔Δੌ͍IoT൘ ŮŧŠźƃɺӡಈͯ͠Δ?ͪΌΜͱ͝൧৯ͯΔ?Α͘৸ΕͯΔ? ͬͯͷ͕͔Δੌ͍IoTϖϯμϯτ
None
ݩؾείΞମॏτϨϯυɺτΠϨճ ɺ৯ࣄճͳͲ ͋ΒΏΔCatlogσʔλΛγΣΞͯ͠͏ͪ ͷࢠࣗຫͰ͖Δػೳ
‣ ༷ʑͳσʔλΛεςοΧʔԽͯ͠ஔ ‣ υϥοάͯ͠ҠಈͰ͖ΔΑ ‣ ը໘্ΑΓ্ʹυϥοάͨ͠ΒআͰ͖ΔΑ ‣ ϐϯνͨ͠ΒζʔϜͰ͖ΔΑ ‣ CenterVerticallyͱ͔CenterHorizontallyʹεφοϓͰ͖ΔΑ
͜ͷը໘ͷΤϯδχΞత໘നΈ
Ͳ͏Μͷ?
‣ Modifier#pointerInput ‣ PointerInputScope#detectDragGesture ‣ PointerInputScope#detectTransformGesture ॆ࣮ͷgesture API
modifier .pointerInput(Unit) { detectDragGestures { change, dragAmount -> state.offset +=
dragAmount } } .graphicsLayer { translationX = state.offset.x translationY = state.offset.y } PointerInput#detectDragGestures
modifier .pointerInput(Unit) { detectTransformGestures { centroid, pan, zoom, rotation ->
state.scale *= zoom } } .graphicsLayer { scaleX = state.scale scaleY = state.scale } PointerInput#detectTransformGestures
‣ PointerInputScope#detectDragGesture ‣ Drag͚͖͍ͩͨ͞ͳΒ͍ͭ͜Λ͑OK ‣ PointerInputScope#detectTransformGesture ‣ DragҎ֎ʹZoomRotationѻ͍͍ͨͳΒ͜Ε ‣ ֤δΣενϟʔͷ͕ಉ࣌ʹ͘ΔͷͰͲͷδΣενϟʔ͕ܧଓதͳ
ͷ͔ผ͍͠ ‣ Zoom͠ͳ͕ΒDragͱ͔Ͱ͖ͪΌ͏ ‣ onGestureStart, onGestureEndίʔϧόοΫແ͍ APIੇධ
suspend fun PointerInputScope.detectTransformGestures( onGestureStart: (GestureType) -> Unit, onGestureEnd: (GestureType) ->
Unit, onDrag: (dragAmount: Offset) -> Unit, onZoom: (zoom: Float) -> Unit, ) { forEachGesture { awaitPointerEventScope { awaitFirstDown(requireUnconsumed = false) val gestureType = detectGesture() ?: return@awaitPointerEventScope onGestureStart(gestureType) do { val event = awaitPointerEvent() when (gestureType) { GestureType.DRAG -> { val dragChange = event.calculatePan() if (dragChange != Offset.Zero) onDrag(dragChange) } GestureType.ZOOM -> { val zoomChange = event.calculateZoom() if (zoomChange != 1f) onZoom(zoomChange) } } event.changes.fastForEach { if (it.positionChanged()) it.consume() } } while (event.changes.fastAny { it.pressed }) onGestureEnd(gestureType) } } } private suspend fun AwaitPointerEventScope.detectGesture(): GestureType? { var zoom = 1f var pan = Offset.Zero val touchSlop = viewConfiguration.touchSlop var gestureType: GestureType? = null do { val event = awaitPointerEvent() zoom *= event.calculateZoom() pan += event.calculatePan() val zoomMotion = abs(1 - zoom) * event.calculateCentroidSize(useCurrent = false) val panMotion = pan.getDistance() if (zoomMotion > touchSlop) { gestureType = GestureType.ZOOM break } if (panMotion > touchSlop) { gestureType = GestureType.DRAG break } } while (event.changes.fastAny { it.pressed }) return gestureType } enum class GestureType { DRAG, ZOOM } ΞϓϦͷཁ݅Λຬͨͤͳ͍ͷͰdetectؔΛࣗͰॻ͍ͨ ※Ջͳͱ͖ʹݟͯͶ https://bit.ly/composegesture
‣ Catlogͷཁ݅తʹdetect͔ؔΒॻ͍ͨ ‣ ը໘֎ͷυϥοάෆՄ ‣ εςοΧʔ͔Βը໘·ͰͷڑΛܭࢉɺͦΕΛ͑Δ dragAmountΔ ‣ υϥοάதʹCenterVertically |
CenterHorizontallyۙʹ͖ͨΒͦ ͜εφοϓ ‣ ը໘ͱεφοϓΛߟྀͯ͠࠷ऴతͳdragAmountΛܾఆ͢Δ ‣ ը໘ͰZoomͨ͠Βը໘֎ʹΈग़ͪΌ͍·͢ΑͶ ‣ Ͱ͔͘ͳͬͯը໘֎ʹग़ͯ͠·ͬͨը໘ͣΒͯ͋͛͠Δ ͩΔ͔ͬͨࣄ
δΣενϟʔ࣮͢Δ͚ͩͳΒ؆୯ ΞϓϦͷཁ݅ʹΑͬͯͪΐͬͱμϧ͍
Thank you