Skip to content

Commit 4a216f6

Browse files
grabbouMartin Konicek
authored and
Martin Konicek
committed
Better error for ART <Group />
Summary: Fixes #3815 Differential Revision: D4295976 Pulled By: javache fbshipit-source-id: 034690d3bee75217d820d3361136a410a812cd2c
1 parent 43d6e8f commit 4a216f6

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Libraries/ART/ReactNativeART.js

+17
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ var ReactNativeViewAttributes = require('ReactNativeViewAttributes');
1919

2020
var createReactNativeComponentClass = require('createReactNativeComponentClass');
2121
var merge = require('merge');
22+
var invariant = require('fbjs/lib/invariant');
2223

2324
// Diff Helpers
2425

@@ -137,6 +138,14 @@ function childrenAsString(children) {
137138
// Surface - Root node of all ART
138139

139140
class Surface extends React.Component {
141+
static childContextTypes = {
142+
isInSurface: React.PropTypes.bool,
143+
};
144+
145+
getChildContext() {
146+
return { isInSurface: true };
147+
}
148+
140149
render() {
141150
var props = this.props;
142151
var w = extractNumber(props.width, 0);
@@ -203,8 +212,16 @@ function extractOpacity(props) {
203212
// ReactART.
204213

205214
class Group extends React.Component {
215+
static contextTypes = {
216+
isInSurface: React.PropTypes.bool.isRequired,
217+
};
218+
206219
render() {
207220
var props = this.props;
221+
invariant(
222+
this.context.isInSurface,
223+
'ART: <Group /> must be a child of a <Surface />'
224+
);
208225
return (
209226
<NativeGroup
210227
opacity={extractOpacity(props)}

0 commit comments

Comments
 (0)