stripe / stripe-react-native

React Native library for Stripe.
https://stripe.dev/stripe-react-native
MIT License
1.27k stars 263 forks source link

Address Element does not close once the user submits(onSubmit) the address for iOS. #1590

Closed SRI-SRINIVASAN-S closed 8 months ago

SRI-SRINIVASAN-S commented 9 months ago

The Address Element does not close once the user submits(onSubmit) the address when I'm handling the state changes after onSubmit only for iOS for Android it updates the state once we click on onSubmit.

Expected behaviour Usually, the address element needs to close once we submit(onSubmit) the address but for iOS the address element does not close after we submit where I can see the address log(User entered address) I have also handled the state changes after onSubmit address. For Android, it closes the address element once we submit the address.

Screenshots The Screenshot below shows the UI of the AddressSheet of the stripe. Simulator Screenshot - iPhone 15 Pro - 2024-01-18 at 12 04 48

Smartphone (please complete the following information):

Additional context

The code below is for the above issue.

const [addressSheetVisible, setAddressSheetVisible] = useState(false); {addressSheetVisible && ( <AddressSheet visible={addressSheetVisible} animationStyle="slide" onSubmit={async addressDetails => { if (Platform.OS === 'ios') { setAddressSheetVisible(false); handleSaveAddress(addressDetails); } else { setAddressSheetVisible(false); handleSaveAddress(addressDetails); } }} onError={error => { if (error.code === AddressSheetError.Failed) { Alert.alert('There was an error.', 'Check the logs for details.'); console.log(error?.localizedMessage); } setAddressSheetVisible(false); }} appearance={{ primaryButton: { colors: { background: '#1450A3', }, }, }} defaultValues={{ address: { country: 'US', city: 'Washington DC', }, }} additionalFields={{ phoneNumber: 'required', }} presentationStyle="popover" allowedCountries={['US', 'CA', 'DE']} primaryButtonTitle={'Use this Address'} sheetTitle={'Shipping Address'} /> )}

charliecruzan-stripe commented 9 months ago

What version of stripe-react-native are you using?

SRI-SRINIVASAN-S commented 9 months ago

Hi charliecruzan

I'm using stripe-react-native Version - 0.35.0 (@stripe/stripe-react-native": "^0.35.0"). This same issue is there in version 0.35.1 also. Where I have updated my version and given it a try.

charliecruzan-stripe commented 8 months ago

this is happening because you're wrapping the component with {addressSheetVisible && ()}. If you remove that, it'll work as expected