fix(web): gesture-model did not check start-item conditions for first source

This commit is contained in:
Joshua A. Horton 2023-09-22 08:59:15 +07:00
parent f23b6e10de
commit 8ca37efcae

View file

@ -237,7 +237,7 @@ export class GestureMatcher<Type> implements PredecessorMatch<Type> {
return this.predecessor.primaryPath;
}
return bestMatcher.source;
return bestMatcher?.source;
}
public get baseItem(): Type {
@ -279,9 +279,19 @@ export class GestureMatcher<Type> implements PredecessorMatch<Type> {
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<Type>) {
// 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<Type> implements PredecessorMatch<Type> {
}
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<Type>) {
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);
});