Skip to content

Commit 68f6d60

Browse files
committed
Actually runs error free
1 parent d8e2229 commit 68f6d60

File tree

7 files changed

+82
-84
lines changed

7 files changed

+82
-84
lines changed

.babelrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"presets": ["react-native"],
3+
"plugins": [
4+
"babel-plugin-transform-es2015-destructuring",
5+
"babel-plugin-transform-object-rest-spread"
6+
]
7+
}

examples/.babelrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2+
"presets": ["react-native"],
23
"plugins": [
34
"babel-plugin-transform-es2015-destructuring",
45
"babel-plugin-transform-object-rest-spread"
5-
],
6-
"presets": ["react-native"]
6+
]
77
}

examples/app/Examples.js

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,41 @@ const styles = StyleSheet.create({
1212
},
1313
});
1414

15+
// const exampleJson = {
16+
// array: [1, 2, 3],
17+
// emptyArray: [],
18+
// bool: true,
19+
// date: new Date(),
20+
// object: {
21+
// foo: {
22+
// bar: 'baz',
23+
// nested: {
24+
// moreNested: {
25+
// evenMoreNested: {
26+
// veryNested: {
27+
// insanelyNested: {
28+
// ridiculouslyDeepValue: 'Hello',
29+
// levels: 9,
30+
// tooMany: true,
31+
// },
32+
// },
33+
// },
34+
// },
35+
// },
36+
// },
37+
// baz: undefined,
38+
// func: function User() {},
39+
// },
40+
// emptyObject: {},
41+
// immutable: Map({ key: 'value' }), // eslint-disable-line new-cap
42+
// hugeArray: Array.from({ length: 100 }).map((_, i) => `item #${i}`),
43+
// longString: 'Loremipsumdolorsitamet,consecteturadipiscingelit.Namtempusipsumutfelisdignissimauctor',
44+
// };
45+
1546
const exampleJson = {
16-
array: [1, 2, 3],
17-
emptyArray: [],
18-
bool: true,
19-
date: new Date(),
20-
object: {
21-
foo: {
22-
bar: 'baz',
23-
nested: {
24-
moreNested: {
25-
evenMoreNested: {
26-
veryNested: {
27-
insanelyNested: {
28-
ridiculouslyDeepValue: 'Hello',
29-
levels: 9,
30-
tooMany: true,
31-
},
32-
},
33-
},
34-
},
35-
},
36-
},
37-
baz: undefined,
38-
func: function User() {},
39-
},
40-
emptyObject: {},
41-
immutable: Map({ key: 'value' }), // eslint-disable-line new-cap
42-
hugeArray: Array.from({ length: 10000 }).map((_, i) => `item #${i}`),
43-
longString: 'Loremipsumdolorsitamet,consecteturadipiscingelit.Namtempusipsumutfelisdignissimauctor.Maecenasodiolectus,finibusegetultricesvel,aliquamutelit.Loremipsumdolorsitamet,consecteturadipiscingelit.Namtempusipsumutfelisdignissimauctor.Maecenasodiolectus,finibusegetultricesvel,aliquamutelit.Loremipsumdolorsitamet,consecteturadipiscingelit.Namtempusipsumutfelisdignissimauctor.Maecenasodiolectus,finibusegetultricesvel,aliquamutelit.' // eslint-disable-line max-len
47+
key: 'val',
48+
secondDey: 2,
49+
nestedArray: [1,2,3]
4450
};
4551

4652
// eslint-disable-next-line
@@ -49,7 +55,6 @@ class Examples extends Component {
4955
return (
5056
<View style={styles.container}>
5157
<Heading>react-native-json-tree</Heading>
52-
<Text>Sub Text</Text>
5358
<JSONTree data={exampleJson} />
5459
</View>
5560
);

examples/package.json

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
11
{
2-
"name": "examples",
3-
"version": "0.0.1",
4-
"private": true,
5-
"scripts": {
6-
"start": "node node_modules/react-native/local-cli/cli.js start",
7-
"android": "react-native run-android",
8-
"ios": "react-native run-ios",
9-
"web": "webpack-dev-server --port 3000 --config web/webpack.config.dev.js --inline --hot --colors --quiet && open http://localhost:3000"
10-
},
112
"dependencies": {
123
"immutable": "3.8.1",
134
"react": "15.2.1",
@@ -18,5 +9,15 @@
189
"babel-preset-react-native": "1.9.0",
1910
"babel-plugin-transform-es2015-destructuring": "6.9.0",
2011
"babel-plugin-transform-object-rest-spread": "6.8.0"
21-
}
12+
},
13+
"name": "examples",
14+
"private": true,
15+
"scripts": {
16+
"android": "react-native run-android",
17+
"ios": "react-native run-ios",
18+
"postinstall": "find node_modules -type f -name .babelrc | grep -v /react-native/ | xargs rm",
19+
"start": "node node_modules/react-native/local-cli/cli.js start",
20+
"web": "webpack-dev-server --port 3000 --config web/webpack.config.dev.js --inline --hot --colors --quiet && open http://localhost:3000"
21+
},
22+
"version": "0.0.1"
2223
}

src/JSONNestedNode.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import ItemRange from './ItemRange';
99
/**
1010
* Renders nested values (eg. objects, arrays, lists, etc.)
1111
*/
12-
1312
function renderChildNodes(props, from, to) {
1413
const {
1514
nodeType,
@@ -20,6 +19,7 @@ function renderChildNodes(props, from, to) {
2019
postprocessValue,
2120
sortObjectKeys,
2221
} = props;
22+
2323
const childNodes = [];
2424

2525
getCollectionEntries(nodeType, data, sortObjectKeys, collectionLimit, from, to).forEach(entry => {
@@ -92,7 +92,7 @@ export default class JSONNestedNode extends React.Component {
9292

9393
// calculate individual node expansion if necessary
9494
const expanded = props.shouldExpandNode && !props.isCircular ?
95-
props.shouldExpandNode(props.keyPath, props.data, props.level) : false;
95+
props.shouldExpandNode(props.keyPath, props.data, props.level) : false;
9696
this.state = {
9797
expanded,
9898
createdChildNodes: false,
@@ -134,6 +134,8 @@ export default class JSONNestedNode extends React.Component {
134134
);
135135
const stylingArgs = [keyPath, nodeType, expanded, expandable];
136136

137+
const onPressItemString = expandable ? this.handlePress : () => {};
138+
137139
return hideRoot ? (
138140
<View {...styling('rootNode', ...stylingArgs)}>
139141
<View {...styling('rootNodeChildren', ...stylingArgs)}>
@@ -152,19 +154,21 @@ export default class JSONNestedNode extends React.Component {
152154
}
153155
<Text
154156
{...styling(['label', 'nestedNodeLabel'], ...stylingArgs)}
155-
onPress={expandable && this.handlePress}
157+
onPress={onPressItemString}
156158
>
157159
{labelRenderer(...stylingArgs)}
158160
</Text>
159161
<Text
160162
{...styling('nestedNodeItemString', ...stylingArgs)}
161-
onPress={expandable && this.handlePress}
163+
onPress={onPressItemString}
162164
>
163165
{renderedItemString}
164166
</Text>
165-
<View {...styling('nestedNodeChildren', ...stylingArgs)}>
166-
{renderedChildren}
167-
</View>
167+
{expanded ?
168+
<View {...styling('nestedNodeChildren', ...stylingArgs)}>
169+
{renderedChildren}
170+
</View> :
171+
null}
168172
</View>
169173
);
170174
}

src/createStylingFromTheme.js

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const getDefaultTheStyling = theme => {
3535
return {
3636
tree: {
3737
backgroundColor: colors.BACKGROUND_COLOR,
38-
border: 0,
38+
borderWidth: 0,
3939
marginBottom: 0.5,
4040
marginLeft: 0.125,
4141
marginRight: 0,
@@ -50,19 +50,12 @@ const getDefaultTheStyling = theme => {
5050
paddingRight: 0,
5151
marginLeft: 0.875,
5252
paddingLeft: keyPath.length > 1 ? 2.125 : 1.25,
53-
// TODO
54-
textIndent: -0.5,
55-
// TODO
56-
wordBreak: 'break-all',
57-
wordWrap: 'break-word',
5853
},
5954
}),
6055

6156
label: { color: colors.LABEL_COLOR },
6257

6358
valueLabel: {
64-
// TODO
65-
// margin: '0 0.5 0 0',
6659
marginBottom: 0.5,
6760
marginLeft: 0.125,
6861
marginRight: 0,
@@ -87,20 +80,15 @@ const getDefaultTheStyling = theme => {
8780
style: {
8881
...style,
8982
marginLeft: 0,
90-
// TODO
91-
transition: '150ms',
92-
transform: expanded ? 'rotateZ(90deg)' : 'rotateZ(0deg)',
93-
transformOrigin: '45% 50%',
83+
transform: expanded ? [{ rotate: '90deg' }] : [{rotate: '0deg' }],
9484
position: 'relative',
95-
lineHeight: 1.1,
9685
fontSize: 0.75,
9786
},
9887
}),
9988

10089
arrowContainer: ({ style }, arrowStyle) => ({
10190
style: {
10291
...style,
103-
display: 'inline-block',
10492
paddingRight: 0.5,
10593
paddingLeft: arrowStyle === 'double' ? 1 : 0,
10694
},
@@ -129,14 +117,11 @@ const getDefaultTheStyling = theme => {
129117
margin: 0,
130118
},
131119

132-
nestedNodeLabel: ({ style }, keyPath, nodeType, expanded, expandable) => ({
120+
nestedNodeLabel: ({ style }) => ({
133121
style: {
134122
...style,
135123
margin: 0,
136124
padding: 0,
137-
WebkitUserSelect: expandable ? 'inherit' : 'text',
138-
MozUserSelect: expandable ? 'inherit' : 'text',
139-
cursor: expandable ? 'pointer' : 'default',
140125
},
141126
}),
142127

@@ -154,21 +139,17 @@ const getDefaultTheStyling = theme => {
154139
marginRight: '0.3',
155140
},
156141

157-
nestedNodeChildren: ({ style }, nodeType, expanded) => ({
142+
nestedNodeChildren: ({ style }, nodeType) => ({
158143
style: {
159144
...style,
160145
padding: 0,
161146
margin: 0,
162-
listStyle: 'none',
163-
display: expanded ? 'block' : 'none',
164147
},
165148
}),
166149

167150
rootNodeChildren: {
168151
padding: 0,
169152
margin: 0,
170-
// TODO
171-
listStyle: 'none',
172153
},
173154
};
174155
};

src/index.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,20 @@ function checkLegacyTheming(theme, props) {
1515
getValueStyle: 'valueText',
1616
};
1717

18-
const deprecatedStylingMethods = Object.keys(deprecatedStylingMethodsMap)
18+
const deprecatedStylingMethods = Object
19+
.keys(deprecatedStylingMethodsMap)
1920
.filter(name => props[name]);
2021

2122
if (deprecatedStylingMethods.length > 0) {
2223
if (typeof theme === 'string') {
23-
theme = {
24-
extend: theme,
25-
};
24+
theme = { extend: theme };
2625
} else {
2726
theme = { ...theme };
2827
}
2928

3029
deprecatedStylingMethods.forEach(name => {
31-
console.error( // eslint-disable-line no-console
32-
`Styling method "${name}" is deprecated, use the "theme" property instead`
33-
);
30+
// eslint-disable-next-line no-console
31+
console.error(`Styling method "${name}" is deprecated, use the "theme" property instead`);
3432

3533
theme[deprecatedStylingMethodsMap[name]] = ({ style }, ...args) => ({
3634
style: {
@@ -49,13 +47,13 @@ class JSONTree extends React.Component {
4947
static propTypes = {
5048
data: PropTypes.oneOfType([
5149
PropTypes.array,
50+
PropTypes.bool,
51+
PropTypes.number,
5252
PropTypes.object,
53+
PropTypes.string,
5354
]).isRequired,
5455
hideRoot: PropTypes.bool,
55-
theme: PropTypes.oneOfType([
56-
PropTypes.object,
57-
PropTypes.string,
58-
]),
56+
theme: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
5957
invertTheme: PropTypes.bool,
6058
keyPath: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number])),
6159
postprocessValue: PropTypes.func,
@@ -91,10 +89,12 @@ class JSONTree extends React.Component {
9189
return (
9290
<View {...styling('tree')}>
9391
<JSONNode
94-
{...{ postprocessValue, hideRoot, styling, ...rest }}
92+
hideRoot={hideRoot}
9593
keyPath={hideRoot ? [] : keyPath}
94+
postprocessValue={postprocessValue}
95+
styling={styling}
9696
value={postprocessValue(value)}
97-
/>
97+
{...rest } />
9898
</View>
9999
);
100100
}

0 commit comments

Comments
 (0)