Skip to content
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

add imperative cardField methods (focus, blur, clear) #337

Merged
merged 5 commits into from
Jul 2, 2021

Conversation

arekkubaczkowski
Copy link
Collaborator

@arekkubaczkowski arekkubaczkowski commented Jun 14, 2021

  • expose CardField methods (focus, blur, clear)
  • inject CardField reference to react-native InputState so the state of card field input can be handled via RN components like ScrollView

There is no need to use StripeContainer anymore since it's registered to RN InputState.

auto keyboard state example:

<ScrollView
      keyboardShouldPersistTaps="never" // <-- add this line 
>
      {children}
 </ScrollView>

example of methods usage:

// App.js

const ref = useRef(null)

const handleFocus = () => {
    ref.current.focus()
}

const handleBlur = () => {
    ref.current.blur()
}

const handleClear = () => {
    ref.current.clear()
}

return (
 <CardField
        ref={ref}
  />
)

Copy link
Contributor

@thorsten-stripe thorsten-stripe left a comment

Choose a reason for hiding this comment

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

LGTM, thanks

@aganov
Copy link
Collaborator

aganov commented Jul 2, 2021

@arekkubaczkowski not sure if you spotted but I've added onBlur support from your prev. PR to the patch. Which as expected only works on iOS. Just FIY in case you've missed it and apparently landed here too...

func paymentCardTextFieldDidEndEditing(_ textField: STPPaymentCardTextField) {
    onFocusChange?(["focusedField": NSNull()])
}

@arekkubaczkowski arekkubaczkowski merged commit 10f8b3e into master Jul 2, 2021
@arekkubaczkowski arekkubaczkowski deleted the feat/focus-blur-clear branch July 2, 2021 08:49
@apperside
Copy link

If someone needs this features in the meanwhile that stripe makes a new release, you can install the library from master

yarn add stripe/stripe-react-native#master

or

npm i stripe/stripe-react-native#master

after installing it, go inside node_modules/@stripe/stripe-react-native , delete the example folder and run yarn or npm i, it should build the library automatically.

At the end of the process, you should have a new lib folder and you should be able to use the library (it worked for me, at least)

@thanhcuong1990
Copy link
Collaborator

Please release this PR soon. Thanks!

@thorsten-stripe
Copy link
Contributor

We'll be releasing a new version later this week. If you need it earlier you can build and install the master branch locally: https://github.com/stripe/stripe-react-native/blob/master/CONTRIBUTING.md#install-library-as-local-repository

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.

5 participants