You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Move away from rnplay to snack, with embedded examples!
Summary:
React Native Playground has been sunset, so I've replaced the examples that previously used it with examples using [Snack](http://snack.expo.io/).
The examples are directly embedded and can be edited live to see updates. The code itself is also in the docs, so we can easily update the docs in one place and we don't have to actually go to a saved app on Snack and update it there.
Run it locally, go to the `Animations` section and the `Direct Manipulation` section.

Open it on your phone, notice that it falls back to just showing plain code.
<img src="https://cloud.githubusercontent.com/assets/90494/24638547/203ec8fc-189e-11e7-99c8-dfabff949f8d.PNG" width="250">
- Get rid of the Expo new user experience dialog that you see when you open a Snack -- is this a dealbreaker
Closes#13285
Differential Revision: D4828011
Pulled By: hramos
fbshipit-source-id: 684ad24a14deb72abb8587ffbb726d316f126d75
import { Text, TouchableOpacity, View } from 'react-native';
100
+
98
101
class MyButton extends React.Component {
99
102
render() {
100
103
return (
@@ -105,7 +108,7 @@ class MyButton extends React.Component {
105
108
}
106
109
}
107
110
108
-
classAppextendsReact.Component {
111
+
export default class App extends React.Component {
109
112
render() {
110
113
return (
111
114
<TouchableOpacity>
@@ -115,7 +118,6 @@ class App extends React.Component {
115
118
}
116
119
}
117
120
```
118
-
[Run this example](https://rnplay.org/apps/JXkgmQ)
119
121
120
122
If you run this you will immediately see this error: `Touchable child
121
123
must either be native or forward setNativeProps to a native component`.
@@ -133,9 +135,12 @@ All we need to do is provide a `setNativeProps` method on our component
133
135
that calls `setNativeProps` on the appropriate child with the given
134
136
arguments.
135
137
136
-
```javascript
138
+
```SnackPlayer?name=Forwarding%20setNativeProps
139
+
import React from 'react';
140
+
import { Text, TouchableOpacity, View } from 'react-native';
141
+
137
142
class MyButton extends React.Component {
138
-
setNativeProps(nativeProps) {
143
+
setNativeProps = (nativeProps) => {
139
144
this._root.setNativeProps(nativeProps);
140
145
}
141
146
@@ -147,8 +152,17 @@ class MyButton extends React.Component {
147
152
)
148
153
}
149
154
}
155
+
156
+
export default class App extends React.Component {
157
+
render() {
158
+
return (
159
+
<TouchableOpacity>
160
+
<MyButton label="Press me!" />
161
+
</TouchableOpacity>
162
+
)
163
+
}
164
+
}
150
165
```
151
-
[Run this example](https://rnplay.org/apps/YJxnEQ)
152
166
153
167
You can now use `MyButton` inside of `TouchableOpacity`! A sidenote for
154
168
clarity: we used the [ref callback](https://facebook.github.io/react/docs/more-about-refs.html#the-ref-callback-attribute) syntax here, rather than the traditional string-based ref.
@@ -173,22 +187,22 @@ use `setNativeProps` to directly manipulate the TextInput value when
173
187
necessary. For example, the following code demonstrates clearing the
174
188
input when you tap a button:
175
189
176
-
```javascript
177
-
classAppextendsReact.Component {
178
-
constructor(props) {
179
-
super(props);
180
-
this.clearText=this.clearText.bind(this);
181
-
}
190
+
```SnackPlayer?name=Clear%20text
191
+
import React from 'react';
192
+
import { TextInput, Text, TouchableOpacity, View } from 'react-native';
182
193
183
-
clearText() {
194
+
export default class App extends React.Component {
0 commit comments