diff --git a/common/web/gesture-recognizer/src/engine/headless/gestures/matchers/gestureMatcher.ts b/common/web/gesture-recognizer/src/engine/headless/gestures/matchers/gestureMatcher.ts index 1c228ce84b..7ac4b8798f 100644 --- a/common/web/gesture-recognizer/src/engine/headless/gestures/matchers/gestureMatcher.ts +++ b/common/web/gesture-recognizer/src/engine/headless/gestures/matchers/gestureMatcher.ts @@ -237,7 +237,7 @@ export class GestureMatcher implements PredecessorMatch { return this.predecessor.primaryPath; } - return bestMatcher.source; + return bestMatcher?.source; } public get baseItem(): Type { @@ -279,9 +279,19 @@ export class GestureMatcher implements PredecessorMatch { throw new Error(`The specified gesture model does not support more than ${existingContacts} contact points.`); } - // The number of already-active contacts tracked for this gesture - const contactSpec = this.model.contacts[existingContacts]; + this.addContactInternal(simpleSource.constructSubview(false, true)); + } + public get result() { + return this._result; + } + + private addContactInternal(simpleSource: GestureSourceSubview) { + // The number of already-active contacts tracked for this gesture + const existingContacts = this.pathMatchers.length; + + const contactSpec = this.model.contacts[existingContacts]; + const contactModel = new PathMatcher(contactSpec.model, simpleSource); let baseItem: Type = null; if(existingContacts) { // just use the highest-priority item source's base item and call it a day. @@ -303,26 +313,13 @@ export class GestureMatcher implements PredecessorMatch { } if(contactSpec.model.allowsInitialState) { - const initialStateCheck = contactSpec.model.allowsInitialState(simpleSource.currentSample, this.primaryPath.currentSample, baseItem); + const initialStateCheck = contactSpec.model.allowsInitialState(simpleSource.currentSample, this.primaryPath?.currentSample, baseItem); if(!initialStateCheck) { this.finalize(false, 'path'); } } - this.addContactInternal(simpleSource.constructSubview(false, true)); - } - - public get result() { - return this._result; - } - - private addContactInternal(simpleSource: GestureSourceSubview) { - const existingContacts = this.pathMatchers.length; - - // The number of already-active contacts tracked for this gesture - const contactSpec = this.model.contacts[existingContacts]; - const contactModel = new PathMatcher(contactSpec.model, simpleSource); contactModel.promise.then((resolution) => { this.finalize(resolution.type == 'resolve', resolution.cause); });