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

fix: align methods with react-native-text-input-mask #12

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function App() {
formatted: '',
});

const onChangeText = React.useCallback((extracted, formatted) => {
const onChangeText = React.useCallback((formatted, extracted) => {
console.log('extracted:', extracted, 'formatted:', formatted);
setTextState({ extracted, formatted });
}, []);
Expand All @@ -37,9 +37,9 @@ export default function App() {
defaultValue=""
value={textState.formatted}
style={styles.maskedTextInput}
onAdvancedMaskTextChange={onChangeText}
onChangeText={onChangeText}
onTailPlaceholderChange={console.log}
primaryMaskFormat="[00]-[$$]-[00]"
mask="[00]-[$$]-[00]"
autocomplete={false}
allowSuggestions={true}
autocompleteOnFocus={false}
Expand Down
12 changes: 6 additions & 6 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React, { forwardRef, memo, useCallback } from 'react';
import MaskedTextInputDecoratorView from './MaskedTextInputNative';
import type { MaskedTextInputDecoratorViewNativeProps } from './types';

type MaskedTextInputProps = TextInputProps &
type MaskedTextInputProps = Omit<TextInputProps, 'onChangeText'> &
MaskedTextInputDecoratorViewNativeProps;

const styles = StyleSheet.create({
Expand Down Expand Up @@ -32,10 +32,10 @@ const MaskedTextInput = memo<MaskedTextInputProps>(
customTransformation,
defaultValue,
isRTL,
primaryMaskFormat,
mask,
autoCapitalize = 'words',
value,
onAdvancedMaskTextChange,
onChangeText,
onTailPlaceholderChange,
...rest
},
Expand All @@ -45,10 +45,10 @@ const MaskedTextInput = memo<MaskedTextInputProps>(

const onAdvancedMaskTextChangeCallback = useCallback(
({ nativeEvent: { extracted, formatted, tailPlaceholder } }) => {
onAdvancedMaskTextChange?.(extracted, formatted);
onChangeText?.(formatted, extracted);
onTailPlaceholderChange?.(tailPlaceholder);
},
[onAdvancedMaskTextChange, onTailPlaceholderChange]
[onChangeText, onTailPlaceholderChange]
);

return (
Expand All @@ -66,7 +66,7 @@ const MaskedTextInput = memo<MaskedTextInputProps>(
defaultValue={defaultValue}
isRTL={isRTL}
onAdvancedMaskTextChange={onAdvancedMaskTextChangeCallback}
primaryMaskFormat={primaryMaskFormat}
primaryMaskFormat={mask}
style={IS_FABRIC ? styles.farAway : styles.displayNone}
value={value}
/>
Expand Down
7 changes: 2 additions & 5 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@ export type Notation = {
};

export type MaskedTextInputDecoratorViewNativeProps = ViewProps & {
primaryMaskFormat: string;
mask: string;
customNotations?: Notation[];
onAdvancedMaskTextChange?: (
extractedValue: string,
formattedValue: string
) => void;
onChangeText?: (formattedValue: string, extractedValue: string) => void;
onTailPlaceholderChange?: (tailPlaceholder: string) => void;
affinityFormat?: string[];
autocomplete?: boolean;
Expand Down
Loading