Skip to content

Commit

Permalink
fix: align methods with react-native-text-input-mask (#12)
Browse files Browse the repository at this point in the history
* fix: align methods with react-native-text-input-mask

* fix: onAdvancedTextChange to onChangeText
  • Loading branch information
IvanIhnatsiuk authored Oct 27, 2024
1 parent 686a36e commit 164f0ac
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
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

0 comments on commit 164f0ac

Please sign in to comment.