-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(core): stop accepting GestureTypes enum as an eventName #10537
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1a690d2
fix(core): stop accepting GestureTypes as eventName
shirakaba 7637aa0
chore(core): introduce GestureTypeNames
shirakaba 988558a
chore(core): get strings directly out of GestureTypes enum keys
shirakaba 3d04060
Merge branch 'main' into gesture-observers-cleanup
NathanWalker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -284,38 +284,42 @@ export interface RotationGestureEventData extends GestureEventDataWithState { | |
* @param separator(optional) - Text separator between gesture type strings. | ||
*/ | ||
export function toString(type: GestureTypes, separator?: string): string { | ||
const types = new Array<string>(); | ||
// We can get stronger typings with `keyof typeof GestureTypes`, but sadly | ||
// indexing into an enum simply returns `string`, so we'd have to type-assert | ||
// all of the below anyway. Even this `(typeof GestureTypes)[GestureTypes]` is | ||
// more for documentation than for type-safety (it resolves to `string`, too). | ||
const types = new Array<(typeof GestureTypes)[GestureTypes]>(); | ||
|
||
if (type & GestureTypes.tap) { | ||
types.push('tap'); | ||
types.push(GestureTypes[GestureTypes.tap]); | ||
} | ||
|
||
if (type & GestureTypes.doubleTap) { | ||
types.push('doubleTap'); | ||
types.push(GestureTypes[GestureTypes.doubleTap]); | ||
} | ||
|
||
if (type & GestureTypes.pinch) { | ||
types.push('pinch'); | ||
types.push(GestureTypes[GestureTypes.pinch]); | ||
} | ||
|
||
if (type & GestureTypes.pan) { | ||
types.push('pan'); | ||
types.push(GestureTypes[GestureTypes.pan]); | ||
} | ||
|
||
if (type & GestureTypes.swipe) { | ||
types.push('swipe'); | ||
types.push(GestureTypes[GestureTypes.swipe]); | ||
} | ||
|
||
if (type & GestureTypes.rotation) { | ||
types.push('rotation'); | ||
types.push(GestureTypes[GestureTypes.rotation]); | ||
} | ||
|
||
if (type & GestureTypes.longPress) { | ||
types.push('longPress'); | ||
types.push(GestureTypes[GestureTypes.longPress]); | ||
} | ||
|
||
if (type & GestureTypes.touch) { | ||
types.push('touch'); | ||
types.push(GestureTypes[GestureTypes.touch]); | ||
} | ||
|
||
return types.join(separator); | ||
|
@@ -327,28 +331,8 @@ export function toString(type: GestureTypes, separator?: string): string { | |
* Returns a gesture type enum value from a string (case insensitive). | ||
* @param type - A string representation of a gesture type (e.g. Tap). | ||
*/ | ||
export function fromString(type: string): GestureTypes { | ||
const t = type.trim().toLowerCase(); | ||
|
||
if (t === 'tap') { | ||
return GestureTypes.tap; | ||
} else if (t === 'doubletap') { | ||
return GestureTypes.doubleTap; | ||
} else if (t === 'pinch') { | ||
return GestureTypes.pinch; | ||
} else if (t === 'pan') { | ||
return GestureTypes.pan; | ||
} else if (t === 'swipe') { | ||
return GestureTypes.swipe; | ||
} else if (t === 'rotation') { | ||
return GestureTypes.rotation; | ||
} else if (t === 'longpress') { | ||
return GestureTypes.longPress; | ||
} else if (t === 'touch') { | ||
return GestureTypes.touch; | ||
} | ||
|
||
return undefined; | ||
export function fromString(type: string): GestureTypes | undefined { | ||
return GestureTypes[type.trim()]; | ||
} | ||
Comment on lines
+334
to
336
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've removed the
To be honest, we can likely remove the |
||
|
||
export abstract class GesturesObserverBase implements GesturesObserverDefinition { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@farfromrefug As requested, now using the string constants instead (forgot how enums worked).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The thing is we have guided people to use the types as explained in old docs for years: https://old.docs.nativescript.org/ui/gestures
How are we going to make up for that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch 🤔
Optimistically, I’d imagine they’d see a compiler error, see that it now accepts only a string, and be able to take a good guess at what the string is (as it comes from the same enum).
Arguably, it’s now left unmentioned in the new docs, so the typings serve as the up-to-date documentation.
I’d rather not handle it at runtime and just pull the plaster, if possible. It’s unlikely to be the only breaking change regarding event-handling that’s to come, so once the dust has settled, we could provide a migration guide based on what makes it into the release. Most likely in the blog post announcing the new release.