Skip to content

feat: add autocomplete for fireEvent event names #1434

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

Conversation

pierrezimmermannbam
Copy link
Collaborator

Summary

This is an attempt to improve fireEvent's DX by adding autocomplete for handler props. fireEvent still accepts any string so this is not a breaking change but it now also comes with an autocomplete. The autocomplete will propose any prop name from ViewProps, TextProps, ScrollViewProps or PressableProps that starts with on but without the on. So for instance MomentumScrollEnd will be proposed because ScrollViewProps has the onMomentumScrollEnd

Capture d’écran 2023-07-18 à 09 41 55

Test plan

I have tested manually the autocomplete and made sure that fireEvent still accepts any string

@pierrezimmermannbam pierrezimmermannbam force-pushed the feat/fireEventAutoComplete branch from 43c1713 to 5288be0 Compare July 18, 2023 07:47
@codecov
Copy link

codecov bot commented Jul 18, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.01 🎉

Comparison is base (5bb5d2d) 97.02% compared to head (696d516) 97.03%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1434      +/-   ##
==========================================
+ Coverage   97.02%   97.03%   +0.01%     
==========================================
  Files          68       68              
  Lines        3863     3882      +19     
  Branches      568      568              
==========================================
+ Hits         3748     3767      +19     
  Misses        115      115              
Impacted Files Coverage Δ
src/fireEvent.ts 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

type StringWithAutoComplete<T> = T | (string & Record<never, never>);

// String union type of keys of T that start with on, stripped from on
type OnKeys<T> = keyof {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice trick! One think I find disturbing is that it's suggesting uppercase names, e.g. Press instead of press. Could you add another step that would make the event name lowercase?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I agree, I updated it so that it's now lowercase

@@ -1,4 +1,10 @@
import { ReactTestInstance } from 'react-test-renderer';
import {
ViewProps,
TextProps,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also add TextInputProps

Copy link
Member

@mdjastrzebski mdjastrzebski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome PR @pierrezimmermannbam! I plant to release a new RNTL (minor) version tomorrow.

@mdjastrzebski mdjastrzebski merged commit 7587e69 into callstack:main Jul 20, 2023
@mdjastrzebski
Copy link
Member

This PR has been released in v12.1.3 🚢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants