Skip to content

Commit

Permalink
Merge pull request #58 from gabrieldonadel/fix/deprecated-react-nativ…
Browse files Browse the repository at this point in the history
…e-prop-types

fix: Proptypes errors on react-native 0.69
  • Loading branch information
gabrieldonadel authored Aug 14, 2022
2 parents ec87fd9 + 9b6c4f1 commit 7402dbe
Show file tree
Hide file tree
Showing 36 changed files with 519 additions and 409 deletions.
4 changes: 2 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ module.exports = {
plugins: ['react-perf'],
extends: ['@react-native-community', 'plugin:react-perf/recommended'],
rules: {
semi: 0,
'semi': 0,
'react-perf/jsx-no-new-object-as-prop': 1,
'react-perf/jsx-no-new-array-as-prop': 0,
'react-perf/jsx-no-new-function-as-prop': 0,
'react-perf/jsx-no-jsx-as-prop': 1,
},
}
};
14 changes: 0 additions & 14 deletions example/__tests__/App-test.js

This file was deleted.

3 changes: 1 addition & 2 deletions example/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ class App extends Component {
<ScrollView
style={styles.scroll}
contentContainerStyle={styles.contentContainer}
keyboardShouldPersistTaps="handled"
>
keyboardShouldPersistTaps="handled">
<View style={styles.container}>
<TextField
ref={this.firstnameRef}
Expand Down
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import TextField from './src/components/field'
import FilledTextField from './src/components/field-filled'
import OutlinedTextField from './src/components/field-outlined'
import TextField from './src/components/field';
import FilledTextField from './src/components/field-filled';
import OutlinedTextField from './src/components/field-outlined';

export { TextField, FilledTextField, OutlinedTextField }
export { TextField, FilledTextField, OutlinedTextField };
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
"preset": "react-native"
},
"dependencies": {
"deprecated-react-native-prop-types": "^2.3.0",
"prop-types": "^15.5.9"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion scripts/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const options = {
};

if (os.type() === 'Windows_NT') {
options.shell = true
options.shell = true;
}

let result;
Expand Down
40 changes: 22 additions & 18 deletions src/components/affix/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import PropTypes from 'prop-types'
import React, { PureComponent } from 'react'
import { Animated, Text } from 'react-native'
import PropTypes from 'prop-types';
import React, { PureComponent } from 'react';
import { Animated } from 'react-native';
import { TextPropTypes } from 'deprecated-react-native-prop-types';

import styles from './styles'
import styles from './styles';

export default class Affix extends PureComponent {
static defaultProps = {
numberOfLines: 1,
}
};

static propTypes = {
numberOfLines: PropTypes.number,
style: Text.propTypes.style,
style: TextPropTypes.style,

color: PropTypes.string.isRequired,
fontSize: PropTypes.number.isRequired,
Expand All @@ -20,41 +21,44 @@ export default class Affix extends PureComponent {

labelAnimation: PropTypes.instanceOf(Animated.Value).isRequired,

children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]),
}
children: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.node),
PropTypes.node,
]),
};

render() {
let { labelAnimation, style, children, type, fontSize, color } = this.props
let { labelAnimation, style, children, type, fontSize, color } = this.props;

let containerStyle = {
height: fontSize * 1.5,
opacity: labelAnimation,
}
};

let textStyle = {
includeFontPadding: false,
textAlignVertical: 'top',

fontSize,
color,
}
};

switch (type) {
case 'prefix':
containerStyle.paddingRight = 8
textStyle.textAlign = 'left'
break
containerStyle.paddingRight = 8;
textStyle.textAlign = 'left';
break;

case 'suffix':
containerStyle.paddingLeft = 8
textStyle.textAlign = 'right'
break
containerStyle.paddingLeft = 8;
textStyle.textAlign = 'right';
break;
}

return (
<Animated.View style={[styles.container, containerStyle]}>
<Animated.Text style={[style, textStyle]}>{children}</Animated.Text>
</Animated.View>
)
);
}
}
4 changes: 2 additions & 2 deletions src/components/affix/styles.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { StyleSheet } from 'react-native'
import { StyleSheet } from 'react-native';

export default StyleSheet.create({
container: {
top: 2,
justifyContent: 'center',
},
})
});
40 changes: 20 additions & 20 deletions src/components/affix/test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'react-native'
import React from 'react'
import { Animated } from 'react-native'
import renderer from 'react-test-renderer'
import 'react-native';
import React from 'react';
import { Animated } from 'react-native';
import renderer from 'react-test-renderer';

import Affix from '.'
import Affix from '.';

/* eslint-env jest */

Expand All @@ -12,10 +12,10 @@ const props = {
fontSize: 16,

labelAnimation: new Animated.Value(1),
}
};

const prefix = 'a'
const suffix = 'z'
const prefix = 'a';
const suffix = 'z';

it('renders prefix', () => {
let affix = renderer
Expand All @@ -24,10 +24,10 @@ it('renders prefix', () => {
{prefix}
</Affix>
)
.toJSON()
.toJSON();

expect(affix).toMatchSnapshot()
})
expect(affix).toMatchSnapshot();
});

it('renders inactive prefix', () => {
let affix = renderer
Expand All @@ -36,10 +36,10 @@ it('renders inactive prefix', () => {
{prefix}
</Affix>
)
.toJSON()
.toJSON();

expect(affix).toMatchSnapshot()
})
expect(affix).toMatchSnapshot();
});

it('renders suffix', () => {
let affix = renderer
Expand All @@ -48,10 +48,10 @@ it('renders suffix', () => {
{suffix}
</Affix>
)
.toJSON()
.toJSON();

expect(affix).toMatchSnapshot()
})
expect(affix).toMatchSnapshot();
});

it('renders inactive suffix', () => {
let affix = renderer
Expand All @@ -60,7 +60,7 @@ it('renders inactive suffix', () => {
{suffix}
</Affix>
)
.toJSON()
.toJSON();

expect(affix).toMatchSnapshot()
})
expect(affix).toMatchSnapshot();
});
21 changes: 11 additions & 10 deletions src/components/counter/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import PropTypes from 'prop-types'
import React, { PureComponent } from 'react'
import { Text } from 'react-native'
import PropTypes from 'prop-types';
import React, { PureComponent } from 'react';
import { Text } from 'react-native';
import { TextPropTypes } from 'deprecated-react-native-prop-types';

import styles from './styles'
import styles from './styles';

export default class Counter extends PureComponent {
static propTypes = {
Expand All @@ -12,24 +13,24 @@ export default class Counter extends PureComponent {
baseColor: PropTypes.string.isRequired,
errorColor: PropTypes.string.isRequired,

style: Text.propTypes.style,
}
style: TextPropTypes.style,
};

render() {
let { count, limit, baseColor, errorColor, style } = this.props
let { count, limit, baseColor, errorColor, style } = this.props;

if (!limit) {
return null
return null;
}

let textStyle = {
color: count > limit ? errorColor : baseColor,
}
};

return (
<Text style={[styles.text, style, textStyle]}>
{count} / {limit}
</Text>
)
);
}
}
4 changes: 2 additions & 2 deletions src/components/counter/styles.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { StyleSheet } from 'react-native'
import { StyleSheet } from 'react-native';

export default StyleSheet.create({
text: {
Expand All @@ -9,4 +9,4 @@ export default StyleSheet.create({
paddingVertical: 2,
marginLeft: 8,
},
})
});
32 changes: 18 additions & 14 deletions src/components/counter/test.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
import 'react-native'
import React from 'react'
import renderer from 'react-test-renderer'
import 'react-native';
import React from 'react';
import renderer from 'react-test-renderer';

import Counter from '.'
import Counter from '.';

/* eslint-env jest */

const props = {
baseColor: 'blue',
errorColor: 'red',
fontSize: 12,
}
};

it('renders null when limit is not set', () => {
let counter = renderer.create(<Counter count={1} {...props} />).toJSON()
let counter = renderer.create(<Counter count={1} {...props} />).toJSON();

expect(counter).toBeNull()
})
expect(counter).toBeNull();
});

it('renders when limit is set', () => {
let counter = renderer.create(<Counter count={1} limit={1} {...props} />).toJSON()
let counter = renderer
.create(<Counter count={1} limit={1} {...props} />)
.toJSON();

expect(counter).toMatchSnapshot()
})
expect(counter).toMatchSnapshot();
});

it('renders when limit is exceeded', () => {
let counter = renderer.create(<Counter count={2} limit={1} {...props} />).toJSON()
let counter = renderer
.create(<Counter count={2} limit={1} {...props} />)
.toJSON();

expect(counter).toMatchSnapshot()
})
expect(counter).toMatchSnapshot();
});
6 changes: 6 additions & 0 deletions src/components/field-filled/__snapshots__/test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ exports[`renders 1`] = `
/>
</View>
<View
pointerEvents="auto"
style={
Object {
"alignSelf": "stretch",
Expand Down Expand Up @@ -214,6 +215,7 @@ exports[`renders accessory 1`] = `
</View>
<Image />
<View
pointerEvents="auto"
style={
Object {
"alignSelf": "stretch",
Expand Down Expand Up @@ -376,6 +378,7 @@ exports[`renders counter 1`] = `
/>
</View>
<View
pointerEvents="auto"
style={
Object {
"alignSelf": "stretch",
Expand Down Expand Up @@ -561,6 +564,7 @@ exports[`renders disabled value 1`] = `
/>
</View>
<View
pointerEvents="auto"
style={
Object {
"alignSelf": "stretch",
Expand Down Expand Up @@ -723,6 +727,7 @@ exports[`renders title 1`] = `
/>
</View>
<View
pointerEvents="auto"
style={
Object {
"alignSelf": "stretch",
Expand Down Expand Up @@ -902,6 +907,7 @@ exports[`renders value 1`] = `
/>
</View>
<View
pointerEvents="auto"
style={
Object {
"alignSelf": "stretch",
Expand Down
Loading

0 comments on commit 7402dbe

Please sign in to comment.