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

🚀 - React Native support #656

Open
nsbarsukov opened this issue Nov 13, 2023 · 2 comments
Open

🚀 - React Native support #656

nsbarsukov opened this issue Nov 13, 2023 · 2 comments
Labels
feature New feature or request scope: react Related to @maskito/react

Comments

@nsbarsukov
Copy link
Member

nsbarsukov commented Nov 13, 2023

Which package(s) are relevant/related to the feature request?

@maskito/react

Description

Problem

Investigate if it is possible to add React Native support.

The following code

import {TextInput, View} from 'react-native';
import {useMaskito} from "@maskito/react";

// ...

const options = {
  mask: /^\d+$/,
}

export default function App() {
  const maskedInputRef = useMaskito({options});

  return (
    <View style={styles.container}>
      <TextInput ref={maskedInputRef}></TextInput>
    </View>
  );
}

throws

TypeError: e.querySelector is not a function (it is undefined)

This error is located at:
    in App (created by withDevTools(App))
    in withDevTools(App)
    in RCTView (created by View)
    in View (created by AppContainer)
    in RCTView (created by View)
    in View (created by AppContainer)
    in AppContainer
    in main(RootComponent), js engine: hermes

Why?
In React Native el.querySelector does not work!


Proposed solution

Try to create adapter for React Native.
Something like:

class MaskitoReactNativeElement extends MaskitoElement {
    constructor(host) {
        this.host = host;
    }

    get value() {
        return this.host.value || '';
    }

    set value(value) {
        this.host.value = value;
    }

    get selectionStart() {
        return this.host.selection?.start;
    }

    get selectionEnd() {
        return this.host.selection?.end;
    }
}

const elementPredicate = el => new MaskitoReactNativeElement(el);

const maskedInputRef = useMaskito({options, elementPredicate});
@nsbarsukov nsbarsukov added feature New feature or request scope: react Related to @maskito/react labels Nov 13, 2023
@github-project-automation github-project-automation bot moved this to 💡 Backlog in Taiga-family Nov 13, 2023
@wesleyguirra
Copy link

how to use with react-native?

@nsbarsukov
Copy link
Member Author

how to use with react-native?

This issue is not solved yet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request scope: react Related to @maskito/react
Projects
No open projects
Status: 💡 Backlog
Development

No branches or pull requests

2 participants