Skip to content

Commit f5f46b6

Browse files
ethansharInbal-Tish
authored andcommitted
Infra/more modifiers support (#509)
* add animated modifier to View * add margins support to TextField
1 parent 43ae3f0 commit f5f46b6

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

src/components/inputs/BaseInput.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export default class BaseInput extends BaseComponent {
6767
super(props);
6868

6969
this.state = {
70+
...this.state,
7071
value: props.value,
7172
focused: false,
7273
valid: false,

src/components/inputs/TextField.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ export default class TextField extends BaseInput {
157157
this.toggleExpandableModal = this.toggleExpandableModal.bind(this);
158158

159159
this.state = {
160+
...this.state,
160161
value: props.value, // for floatingPlaceholder functionality
161162
floatingPlaceholderState: new Animated.Value(this.shouldFloatPlaceholder(props.value) ? 1 : 0),
162163
showExpandableModal: false
@@ -553,11 +554,12 @@ export default class TextField extends BaseInput {
553554
}
554555

555556
render() {
557+
const {margins} = this.state;
556558
const {expandable, containerStyle, underlineColor, useTopErrors, hideUnderline} = this.getThemeProps();
557559
const underlineStateColor = this.getStateColor(underlineColor, true);
558560

559561
return (
560-
<View style={[this.styles.container, containerStyle]} collapsable={false}>
562+
<View style={[this.styles.container, margins, containerStyle]} collapsable={false}>
561563
{this.shouldShowTopError() ? this.renderError(useTopErrors) : this.renderTitle()}
562564

563565
<View

src/components/view/index.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import PropTypes from 'prop-types';
22
import React, {PureComponent} from 'react';
3-
import {View as RNView, ViewPropTypes, SafeAreaView} from 'react-native';
3+
import {View as RNView, ViewPropTypes, SafeAreaView, Animated} from 'react-native';
44
import {BaseComponent, asBaseComponent, forwardRef} from '../../commons';
55
import * as Constants from '../../helpers/Constants';
66

@@ -20,8 +20,21 @@ class View extends PureComponent {
2020
* If true, will render as SafeAreaView
2121
*/
2222
useSafeArea: PropTypes.bool,
23+
/**
24+
* Use Animate.View as a container
25+
*/
26+
animated: PropTypes.bool
2327
};
2428

29+
constructor(props) {
30+
super(props);
31+
32+
this.Container = props.useSafeArea && Constants.isIOS ? SafeAreaView : RNView;
33+
if (props.animated) {
34+
this.Container = Animated.createAnimatedComponent(this.Container);
35+
}
36+
}
37+
2538
// TODO: do we need this?
2639
setNativeProps(nativeProps) {
2740
this._root.setNativeProps(nativeProps); // eslint-disable-line
@@ -41,7 +54,7 @@ class View extends PureComponent {
4154
...others
4255
} = this.props;
4356
const {backgroundColor, borderRadius, paddings, margins, alignments, flexStyle} = modifiers;
44-
const Element = useSafeArea && Constants.isIOS ? SafeAreaView : RNView;
57+
const Element = this.Container;
4558

4659
return (
4760
<Element

0 commit comments

Comments
 (0)