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

Paddings are sometimes not applied to ExpirationDateEditText #18

Closed
mihaildu opened this issue May 10, 2023 · 0 comments
Closed

Paddings are sometimes not applied to ExpirationDateEditText #18

mihaildu opened this issue May 10, 2023 · 0 comments

Comments

@mihaildu
Copy link

Hello! A bit of a shot in the dark here, but I tried following this repo example to export a component to react native and I ran into a weird error. Maybe someone just having a look over my code can spot the problem. I have a simple setup

CardExpirationDateManager.java

public class CardExpirationDateManager extends ViewGroupManager<VGSTextInputLayout> {

    protected ExpirationDateEditText input;
    protected VGSTextInputLayout layout;

    public String getName() {
        return "VGSExpDateTextField";
    }

    protected ExpirationDateEditText createInput(ThemedReactContext reactContext) {
        ExpirationDateEditText input = new ExpirationDateEditText(reactContext);
        input.setPadding(21,0,21,0);
        input.setTextColor(Color.BLACK);
        input.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
        input.setDatePickerMode(DatePickerMode.SPINNER);
        input.setDateRegex("MM/YYYY");
        input.setFieldName("card_expirationDate");
        input.setIsRequired(true);
        return input;
    }

    private VGSTextInputLayout createLayout(ThemedReactContext reactContext) {
        VGSTextInputLayout layout = new VGSTextInputLayout(reactContext);
        layout.setBoxCornerRadius(8, 8, 8, 8);
        layout.setHint("Expiration Date");
        return layout;
    }

    @NonNull
    @Override
    protected VGSTextInputLayout createViewInstance(@NonNull ThemedReactContext reactContext) {
        layout = createLayout(reactContext);
        input = createInput(reactContext);
        layout.addView(input);
        return layout;
    }
}

CollectCardExpirationDatePackage.java

public class CollectCardExpirationDatePackage implements ReactPackage {
    @Override
    public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) {
        return Collections.EMPTY_LIST;
    }

    @SuppressWarnings("rawtypes")
    @NonNull
    @Override
    public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) {
        return Collections.singletonList(new CardExpirationDateManager());
    }
}

I add this package in my MainApplication.java

// protected List<ReactPackage> getPackages()
packages.add(new CollectCardExpirationDatePackage());

Then I use it in react native

const ExpDateTextField = requireNativeComponent('VGSExpDateTextField');
...
<ExpDateTextField style={{height: 56, margin: 8}} />

The component works just fine, but when the component renders, sometimes the padding left for the hint is applied and sometimes it's not. It seems like a race condition but can't really figure it out

Screenshot_20230510-141033

Screenshot_20230510-141055

Any ideas? Thanks a lot!

@DmytroDm DmytroDm closed this as completed Sep 9, 2024
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

No branches or pull requests

2 participants