Skip to content

Commit bfd076b

Browse files
authored
Merge pull request #126 from Gamma169/master
Replace spread operator with StyleSheet.flatten for styles
2 parents bac024d + 0296fbd commit bfd076b

File tree

1 file changed

+76
-63
lines changed

1 file changed

+76
-63
lines changed

Diff for: src/index.tsx

+76-63
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
ImageStyle,
2020
TouchableWithoutFeedback,
2121
LayoutChangeEvent,
22+
StyleSheet,
2223
} from 'react-native';
2324
import Animated, {
2425
EasingNode,
@@ -218,14 +219,16 @@ const FloatingLabelInput: React.ForwardRefRenderFunction<InputRef, Props> = (
218219
const [secureText, setSecureText] = useState(true);
219220
const inputRef = useRef<any>(null);
220221

221-
customLabelStyles = {
222-
fontSizeFocused: 10,
223-
fontSizeBlurred: 14,
224-
colorFocused: '#49658c',
225-
colorBlurred: '#49658c',
226-
...setGlobalStyles?.customLabelStyles,
227-
...customLabelStyles,
228-
};
222+
customLabelStyles = StyleSheet.flatten([
223+
{
224+
fontSizeFocused: 10,
225+
fontSizeBlurred: 14,
226+
colorFocused: '#49658c',
227+
colorBlurred: '#49658c',
228+
},
229+
setGlobalStyles?.customLabelStyles,
230+
customLabelStyles,
231+
]);
229232

230233
const [fontColorAnimated] = useState(new Animated.Value(0));
231234

@@ -499,32 +502,34 @@ const FloatingLabelInput: React.ForwardRefRenderFunction<InputRef, Props> = (
499502
? customShowPasswordImage || makeVisibleWhite
500503
: customHidePasswordImage || makeInvisibleWhite;
501504

502-
const style: TextStyle = {
503-
...setGlobalStyles?.labelStyles,
504-
...labelStyles,
505-
left: labelStyles?.left !== undefined ? labelStyles?.left : 5,
506-
fontSize: staticLabel
507-
? customLabelStyles?.fontSizeFocused !== undefined
508-
? customLabelStyles.fontSizeFocused
509-
: 10
510-
: !isFocusedState
511-
? customLabelStyles.fontSizeBlurred
512-
: customLabelStyles.fontSizeFocused,
513-
// @ts-ignore
514-
color: interpolateColors(fontColorAnimated, {
515-
inputRange: [0, 1],
516-
outputColorRange: [
517-
// @ts-ignore
518-
customLabelStyles.colorBlurred,
519-
// @ts-ignore
520-
customLabelStyles.colorFocused,
521-
],
522-
}),
523-
alignSelf: 'center',
524-
position: 'absolute',
525-
flex: 1,
526-
zIndex: 999,
527-
};
505+
const style: TextStyle = StyleSheet.flatten([
506+
setGlobalStyles?.labelStyles,
507+
labelStyles,
508+
{
509+
left: labelStyles?.left !== undefined ? labelStyles?.left : 5,
510+
fontSize: staticLabel
511+
? customLabelStyles?.fontSizeFocused !== undefined
512+
? customLabelStyles.fontSizeFocused
513+
: 10
514+
: !isFocusedState
515+
? customLabelStyles.fontSizeBlurred
516+
: customLabelStyles.fontSizeFocused,
517+
// @ts-ignore
518+
color: interpolateColors(fontColorAnimated, {
519+
inputRange: [0, 1],
520+
outputColorRange: [
521+
// @ts-ignore
522+
customLabelStyles.colorBlurred,
523+
// @ts-ignore
524+
customLabelStyles.colorFocused,
525+
],
526+
}),
527+
alignSelf: 'center',
528+
position: 'absolute',
529+
flex: 1,
530+
zIndex: 999,
531+
},
532+
]);
528533

529534
let input: TextStyle =
530535
inputStyles !== undefined
@@ -533,13 +538,15 @@ const FloatingLabelInput: React.ForwardRefRenderFunction<InputRef, Props> = (
533538
? setGlobalStyles.inputStyles
534539
: styles.input;
535540

536-
input = {
537-
...input,
538-
flex: 1,
539-
color:
540-
input.color !== undefined ? input.color : customLabelStyles.colorFocused,
541-
zIndex: style?.zIndex !== undefined ? style.zIndex - 2 : 0,
542-
};
541+
input = StyleSheet.flatten([
542+
input,
543+
{
544+
flex: 1,
545+
color:
546+
input.color !== undefined ? input.color : customLabelStyles.colorFocused,
547+
zIndex: style?.zIndex !== undefined ? style.zIndex - 2 : 0,
548+
}
549+
]);
543550

544551
containerStyles =
545552
containerStyles !== undefined
@@ -548,13 +555,15 @@ const FloatingLabelInput: React.ForwardRefRenderFunction<InputRef, Props> = (
548555
? setGlobalStyles?.containerStyles
549556
: styles.container;
550557

551-
containerStyles = {
552-
...containerStyles,
553-
alignItems: 'center',
554-
flexDirection: 'row',
555-
flex: 1,
556-
zIndex: style?.zIndex !== undefined ? style.zIndex - 6 : 0,
557-
};
558+
containerStyles = StyleSheet.flatten([
559+
containerStyles,
560+
{
561+
alignItems: 'center',
562+
flexDirection: 'row',
563+
flex: 1,
564+
zIndex: style?.zIndex !== undefined ? style.zIndex - 6 : 0,
565+
}
566+
]);
558567

559568
let toggleButton =
560569
showPasswordContainerStyles !== undefined
@@ -563,10 +572,12 @@ const FloatingLabelInput: React.ForwardRefRenderFunction<InputRef, Props> = (
563572
? setGlobalStyles.showPasswordContainerStyles
564573
: styles.toggleButton;
565574

566-
toggleButton = {
567-
...toggleButton,
568-
alignSelf: 'center',
569-
};
575+
toggleButton = StyleSheet.flatten([
576+
toggleButton,
577+
{
578+
alignSelf: 'center',
579+
},
580+
]);
570581

571582
let img =
572583
showPasswordImageStyles !== undefined
@@ -575,17 +586,19 @@ const FloatingLabelInput: React.ForwardRefRenderFunction<InputRef, Props> = (
575586
? setGlobalStyles.showPasswordImageStyles
576587
: styles.img;
577588

578-
img = {
579-
height: 25,
580-
width: 25,
581-
...img,
582-
};
583-
584-
const countdown = {
585-
...styles.countdown,
586-
...setGlobalStyles?.showCountdownStyles,
587-
...showCountdownStyles,
588-
};
589+
img = StyleSheet.flatten([
590+
{
591+
height: 25,
592+
width: 25,
593+
},
594+
img,
595+
]);
596+
597+
const countdown = StyleSheet.flatten([
598+
styles.countdown,
599+
setGlobalStyles?.showCountdownStyles,
600+
showCountdownStyles,
601+
]);
589602

590603
function onChangeTextCallback(val: string): void | undefined {
591604
if (onChangeText === undefined) return undefined;

0 commit comments

Comments
 (0)