-
Notifications
You must be signed in to change notification settings - Fork 734
Migrate Hint component to TypeScript #1281
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
Conversation
visible={this.showHint} | ||
animationType="none" | ||
transparent | ||
onBackgroundPress={onBackgroundPress} | ||
onRequestClose={onBackgroundPress} | ||
onRequestClose={onBackgroundPress as () => void} |
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.
Why the change of type to () => void
?
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.
because onRequestClose
expects a function with () => void
signature, however onBackgroundPress
has (event: GestureResponderEvent) => void
. Therefore I'm adding a type assertion here.
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.
This looks like a bug, because the user that sends the onBackgroundPress
can expect to receive an event
and may rely on it. I think you need to change the prop to:
onBackgroundPress?: (event?: GestureResponderEvent) => void;
(and remove the as () => void
)
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.
I think it's actually the other way around.
ModalProps
( in src/components/modal/index.tsx
) is defined:
/**
* allow dismissing a modal when clicking on its background
*/
onBackgroundPress?: (event: GestureResponderEvent) => void;
Whereas onRequestClose
is defined:
/**
* The `onRequestClose` prop allows passing a function that will be called once the modal has been dismissed.
* _On the Android platform, this is a required function._
*/
onRequestClose?: () => void;
IMO it's important to keep the onBackgroundPress
definition as is because if the user uses onBackgroundPress
prop then event
should always be defined (as you've described). onRequestClose
, however does not expect a function argument, so we can override it. I think the only reason we use onRequestClose
is because it's a required function for android (onBackgroundPress
is what should actually dismiss the modal) . Alternatively, maybe we could even have something like onRequestClose={this.noop}
(noop = () => {}
)?
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.
Maybe we should take this offline.
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.
Nice work and thank you!
I've left some comments, you also need to update generatedTypes
(it's a little duplication of src/index
:/ ).
There are some things that I'd like to see changed, but I'm not sure how easy they are, feel free to try:
- Changing the
refs
to something other thanany
. - Reducing the number of
interfaces
, I've suggested one, you can open a ticket on this if you don't see other improvements - this might require some infra work.
visible={this.showHint} | ||
animationType="none" | ||
transparent | ||
onBackgroundPress={onBackgroundPress} | ||
onRequestClose={onBackgroundPress} | ||
onRequestClose={onBackgroundPress as () => void} |
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.
This looks like a bug, because the user that sends the onBackgroundPress
can expect to receive an event
and may rely on it. I think you need to change the prop to:
onBackgroundPress?: (event?: GestureResponderEvent) => void;
(and remove the as () => void
)
Oh, another thing, the branch name should be something a little more specific (maybe |
…ve-ui-lib into component-migration-to-ts
@M-i-k-e-l thanks for your time reviewing this. Is there anything else left for me to address? |
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.
Nice work, I think there are only two things left, maybe we should talk about the onBackgroundPress
Description
This PR migrates Hint component and its example screen to TypeScript.
Changelog
Removes manual typings in
Hint.d.ts