react-native/website/core/WebPlayer.js
Devin Abbott 43231c0524 Update web player and add it to UsingAListView docs page.
Summary:
Update web player (which now uses 0.0.29 of react-native-web) to support ListView. lacker

**Test plan (required)**

![screen shot 2016-07-05 at 7 15 08 pm](https://cloud.githubusercontent.com/assets/1198882/16605576/10f80956-42e5-11e6-8b19-4b8242625d23.png)
Closes https://github.com/facebook/react-native/pull/8591

Differential Revision: D3521276

Pulled By: JoelMarcey

fbshipit-source-id: 896a7ee77b9592f7cf95d6d48e5f4ddea76f5f07
2016-07-05 20:13:40 -07:00

71 lines
1.9 KiB
JavaScript

/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule WebPlayer
*/
var React = require('React');
var Prism = require('Prism');
var WEB_PLAYER_VERSION = '1.1.0';
/**
* Use the WebPlayer by including a ```ReactNativeWebPlayer``` block in markdown.
*
* Optionally, include url parameters directly after the block's language. For
* the complete list of url parameters, see: https://github.com/dabbott/react-native-web-player
*
* E.g.
* ```ReactNativeWebPlayer?platform=android
* import React from 'react';
* import { AppRegistry, Text } from 'react-native';
*
* const App = () => <Text>Hello World!</Text>;
*
* AppRegistry.registerComponent('MyApp', () => App);
* ```
*/
var WebPlayer = React.createClass({
parseParams: function(paramString) {
var params = {};
if (paramString) {
var pairs = paramString.split('&');
for (var i = 0; i < pairs.length; i++) {
var pair = pairs[i].split('=');
params[pair[0]] = pair[1];
}
}
return params;
},
render: function() {
var hash = `#code=${encodeURIComponent(this.props.children)}`;
if (this.props.params) {
hash += `&${this.props.params}`;
}
return (
<div className={'web-player'}>
<Prism>{this.props.children}</Prism>
<iframe
style={{marginTop: 4}}
width='880'
height={this.parseParams(this.props.params).platform === 'android' ? '425' : '420'}
data-src={`//npmcdn.com/react-native-web-player@${WEB_PLAYER_VERSION}/index.html${hash}`}
frameBorder='0'
/>
</div>
);
},
});
module.exports = WebPlayer;