react-native/website/core/WebPlayer.js
Devin Abbott 7596e1aaec In docs, bump web player version to fix chromium rendering issue
Summary:
Updates the docs to use the latest version of React Native Web Player.

Fixes rendering issue on Ubuntu + Chromium: #10634

Before:
![ubuntu_64-bit_16_04](https://cloud.githubusercontent.com/assets/1198882/19876803/d687093e-9f96-11e6-9fd3-b3fe66d07ae6.png)

After:
![ubuntu_64-bit_16_04_and_windows_10_x64](https://cloud.githubusercontent.com/assets/1198882/19876807/dcfdf548-9f96-11e6-80c2-d0ab34b41cb0.png)
Closes https://github.com/facebook/react-native/pull/10667

Differential Revision: D4111783

Pulled By: hramos

fbshipit-source-id: df755f87c52e81b784fdcfa99ff77357b194d03e
2016-11-09 19:58:39 -08: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.2.6';
/**
* 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={`//cdn.rawgit.com/dabbott/react-native-web-player/gh-v${WEB_PLAYER_VERSION}/index.html${hash}`}
frameBorder='0'
/>
</div>
);
},
});
module.exports = WebPlayer;