Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect Siri Remote swipe in SwiftUI

How can you recognise Siri Remote swipe gestures from SwiftUI.

I seems like it has not yet been implemented, so how can I get around that?

like image 505
Per Møller Avatar asked Dec 09 '19 13:12

Per Møller


1 Answers

i have 2 answers for this question, i will answer them separately and let you guys decide which is best,

first is the apple way (which obviously doesn't work allways, there are more clicks captured then swipes):

import SwiftUI

struct SwipeTestView: View
{
    var body: some View
    {
        Text("This can be some full screen image or what not")
            .focusable() // <-- this is a must
            .onMoveCommand { direction in  // <-- this $#!* can't tell a move swipe from a touch (direction is of type: MoveCommandDirection)
                print("Direction: \(direction)")
                if direction == .left { print(">>> left swipe detected") }
                if direction == .right { print(">>> right swipe detected") }
                if direction == .up { print(">>> up swipe detected") }
                if direction == .down { print(">>> down swipe detected") }
            }

    }
}

you really (and i can't emphasize this enough) have to swipe on the very edge of the Siri-remote or the iPhone Siri remote widget,

so try to swipe on these yellow areas and try not to tap you'r finger and then swipe, rather gently swipe outwards and let you'r finger get outside of the remote edge completely

Swipe areas

Result expected:

XCode log

i literally tried 100+ times before successfully captured a swipe (clearly not something for production), hopefully tvOS 15 and higher will fix this

like image 199
Shaybc Avatar answered Nov 13 '22 10:11

Shaybc