Skip to content

Commit

Permalink
feat: add missed exports
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanIhnatsiuk committed Nov 1, 2024
1 parent 323d9fd commit 2228de5
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 79 deletions.
2 changes: 1 addition & 1 deletion example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';

import { Button, StyleSheet, Text, View } from 'react-native';
import MaskedTextInput from 'react-native-advanced-input-mask';
import { MaskedTextInput } from 'react-native-advanced-input-mask';

const alphaNumericChars =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
Expand Down
2 changes: 1 addition & 1 deletion jest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const AFFINITY_CALCULATION_STRATEGY = {
};

const mock = {
default: TextInput,
MaskedTextInput: TextInput,
AFFINITY_CALCULATION_STRATEGY,
};

Expand Down
81 changes: 6 additions & 75 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,79 +1,10 @@
import type { TextInputProps } from 'react-native';
import { StyleSheet, TextInput } from 'react-native';
import React, { forwardRef, memo, useCallback } from 'react';
import MaskedTextInputDecoratorView from './MaskedTextInputNative';
import type { MaskedTextInputDecoratorViewNativeProps } from './types';
import MaskedTextInput from './views/MaskedTextInput';

type MaskedTextInputProps = Omit<TextInputProps, 'onChangeText'> &
MaskedTextInputDecoratorViewNativeProps;
import type { MaskedTextInputProps } from './types';
import { AFFINITY_CALCULATION_STRATEGY } from './enums';

const styles = StyleSheet.create({
displayNone: {
display: 'none',
},
farAway: {
position: 'absolute',
top: 1e8,
left: 1e8,
},
});
export type { MaskedTextInputProps };

const MaskedTextInput = memo<MaskedTextInputProps>(
forwardRef<TextInput, MaskedTextInputProps>(
(
{
affinityCalculationStrategy,
affinityFormat,
allowSuggestions,
autocomplete,
autocompleteOnFocus,
autoSkip,
customNotations,
customTransformation,
defaultValue,
isRTL,
mask,
autoCapitalize = 'words',
value,
onChangeText,
onTailPlaceholderChange,
...rest
},
ref
) => {
const IS_FABRIC = 'nativeFabricUIManager' in global;
export { AFFINITY_CALCULATION_STRATEGY };

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

return (
<>
<TextInput {...rest} autoCapitalize={autoCapitalize} ref={ref} />
<MaskedTextInputDecoratorView
affinityCalculationStrategy={affinityCalculationStrategy}
affinityFormat={affinityFormat}
allowSuggestions={allowSuggestions}
autocomplete={autocomplete}
autocompleteOnFocus={autocompleteOnFocus}
autoSkip={autoSkip}
customNotations={customNotations}
customTransformation={customTransformation}
defaultValue={defaultValue}
isRTL={isRTL}
onAdvancedMaskTextChange={onAdvancedMaskTextChangeCallback}
primaryMaskFormat={mask}
style={IS_FABRIC ? styles.farAway : styles.displayNone}
value={value}
/>
</>
);
}
)
);

export default MaskedTextInput;
export { MaskedTextInput };
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ViewProps } from 'react-native';
import type { TextInputProps } from 'react-native';
import type { AFFINITY_CALCULATION_STRATEGY } from './enums';

export type Notation = {
Expand All @@ -21,7 +21,7 @@ type CustomTransformation = {
transformationString: string;
};

export type MaskedTextInputDecoratorViewNativeProps = ViewProps & {
export type MaskedTextInputProps = Omit<TextInputProps, 'onChangeText'> & {
/**
* The mask format to be applied to the text input.
* @example "[0000] [0000] [0000] [0000]"
Expand Down
75 changes: 75 additions & 0 deletions src/views/MaskedTextInput/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { StyleSheet, TextInput } from 'react-native';
import React, { forwardRef, memo, useCallback } from 'react';
import MaskedTextInputDecoratorView from '../../MaskedTextInputNative';
import type { MaskedTextInputProps } from '../../types';

const styles = StyleSheet.create({
displayNone: {
display: 'none',
},
farAway: {
position: 'absolute',
top: 1e8,
left: 1e8,
},
});

const MaskedTextInput = memo<MaskedTextInputProps>(
forwardRef<TextInput, MaskedTextInputProps>(
(
{
affinityCalculationStrategy,
affinityFormat,
allowSuggestions,
autocomplete,
autocompleteOnFocus,
autoSkip,
customNotations,
customTransformation,
defaultValue,
isRTL,
mask,
autoCapitalize = 'words',
value,
onChangeText,
onTailPlaceholderChange,
...rest
},
ref
) => {
const IS_FABRIC = 'nativeFabricUIManager' in global;

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

return (
<>
<TextInput {...rest} autoCapitalize={autoCapitalize} ref={ref} />
<MaskedTextInputDecoratorView
affinityCalculationStrategy={affinityCalculationStrategy}
affinityFormat={affinityFormat}
allowSuggestions={allowSuggestions}
autocomplete={autocomplete}
autocompleteOnFocus={autocompleteOnFocus}
autoSkip={autoSkip}
customNotations={customNotations}
customTransformation={customTransformation}
defaultValue={defaultValue}
isRTL={isRTL}
onAdvancedMaskTextChange={onAdvancedMaskTextChangeCallback}
primaryMaskFormat={mask}
style={IS_FABRIC ? styles.farAway : styles.displayNone}
value={value}
/>
</>
);
}
)
);

export default MaskedTextInput;

0 comments on commit 2228de5

Please sign in to comment.