processGesture method

void processGesture(
  1. GestureType gesture
)

Processes an incoming gesture and matches it against the pattern sequence.

If the gesture matches the current expected gesture in the sequence, the GesturePatternRecognizer advances to the next gesture. If the pattern is completed successfully within the timeout, the onPatternMatched callback is invoked. If there is a mismatch or the time frame is exceeded, the pattern is reset.

gesture is the gesture to process and match against the pattern.

Implementation

void processGesture(GestureType gesture) {
  if (_currentIndex == 0) {
    _startTimer();
  } else if (!_isWithinTimeFrame()) {
    resetPattern();
    return;
  }

  if (_gestureSequence[_currentIndex] == gesture) {
    _currentIndex++;

    if (_currentIndex == _gestureSequence.length) {
      onPatternMatched();
      resetPattern();
    }
  } else {
    resetPattern();
  }
}