pointer

– import “gomatcha.io/matcha/pointer”

Package pointer implements gesture recognizers.

Create the pointer recognizer in the Build function.

 func (v *MyView) Build(ctx view.Context) view.Model {
    tap := &pointer.TapGesture{
        Count: 1,
        OnEvent: func(e *pointer.TapEvent) {
            if e.Kind == pointer.EventKindRecognized {
                // Respond to pointer events. This callback occurs on main thread.
                fmt.Println("view tapped")
            }
        },
    }
    ...

Attach the recognizer to the view.

    ...
    return view.Model{
        Options: []view.Option{
            pointer.GestureList{tap},
        },
    }
 }

type ButtonEvent

type ButtonEvent struct {
	Timestamp time.Time
	Inside    bool
	Kind      EventKind
}

ButtonEvent is emitted by ButtonRecognizer, representing its current state.

type ButtonGesture

type ButtonGesture struct {
	Key           int64
	OnEvent       func(e *ButtonEvent)
	IgnoresScroll bool
}

ButtonGesture is a discrete recognizer that mimics the behavior of a button. The recognizer will fail if the touch ends outside of the view’s bounds.

func (*ButtonGesture) Build

func (r *ButtonGesture) Build() Model

func (*ButtonGesture) TouchKey

func (r *ButtonGesture) TouchKey() int64

type EventKind

type EventKind int

EventKind are the possible recognizer states

Discrete gestures:

EventKindPossible -> EventKindFailed
EventKindPossible -> EventKindRecognized

Continuous gestures:

EventKindPossible -> EventKindFailed
EventKindPossible -> EventKindRecognized
EventKindPossible -> EventKindChanged(optionally) -> EventKindFailed
EventKindPossible -> EventKindChanged(optionally) -> EventKindRecognized
const (
	// Finger is down, but before gesture has been recognized.
	EventKindPossible EventKind = iota
	// After the continuous gesture has been recognized, while the finger is still down. Only for continuous recognizers.
	EventKindChanged
	// Gesture recognition failed or cancelled.
	EventKindFailed
	// Gesture recognition succeded.
	EventKindRecognized
)

type Gesture

type Gesture interface {
	Build() Model
	TouchKey() int64
}

type GestureList

type GestureList []Gesture

func (GestureList) OptionKey

func (r GestureList) OptionKey() string

type Model

type Model struct {
	NativeViewName  string
	NativeViewState proto.Message
	NativeFuncs     map[string]interface{}
}

type PressEvent

type PressEvent struct {
	Kind      EventKind // TODO(KD): Does this work?
	Timestamp time.Time
	Position  layout.Point
	Duration  time.Duration
}

PressEvent is emitted by PressRecognizer, representing its current state.

type PressGesture

type PressGesture struct {
	Key         int64
	MinDuration time.Duration
	OnEvent     func(e *PressEvent)
}

PressGesture is a continuous recognizer that detects single presses with a given duration.

func (*PressGesture) Build

func (r *PressGesture) Build() Model

func (*PressGesture) TouchKey

func (r *PressGesture) TouchKey() int64

type TapEvent

type TapEvent struct {
	Kind      EventKind
	Timestamp time.Time
	Position  layout.Point
}

TapEvent is emitted by TapGesture, representing its current state.

type TapGesture

type TapGesture struct {
	Key     int64
	Count   int
	OnEvent func(*TapEvent)
}

PressRecognizer is a discrete recognizer that detects a number of taps.

func (*TapGesture) Build

func (r *TapGesture) Build() Model

func (*TapGesture) TouchKey

func (r *TapGesture) TouchKey() int64