forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add react-native-web-player to core components docs
Summary: This PR adds the interactive [React Native Web Player](http://dabbott.github.io/react-native-web-player/) to the docs. The web player is an embeddable iframe which runs React Native code using components from [react-native-web](https://github.com/necolas/react-native-web). For now, it's primarily for educational purposes, since only the basic components are implemented. Some details: - The iframe is loaded from MaxCDN using rawgit, locked down to a git tag. - Asset paths (i.e. images) are resolved relative to `//facebook.github.io/react-native/` - When viewed on mobile, it falls back to the syntax-highlighted code blocks. The WebPlayer can be inserted into markdown by using the fences: ``` ```ReactNativeWebPlayer import ... AppRegistry.registerComponent ... `` ` ``` ![screen shot 2016-06-22 at 12 46 50 pm](https://cloud.githubusercontent.com/assets/1198882/16281068/7056804e-3877-11e6-82f7-ece245690548.png) I didn't actually add the WebPlayer to any docs pages in this PR. That we c Closes facebook#8328 Differential Revision: D3471527 Pulled By: lacker fbshipit-source-id: 704da41cd77e08c7e2bc820557a74d36e88e8eb7
- Loading branch information
1 parent
bf1fc86
commit db04093
Showing
4 changed files
with
114 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* 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'); | ||
|
||
/** | ||
* 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)}&runApp=AwesomeProject`; | ||
|
||
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/v0.1.2/index.html${hash}`} | ||
frameBorder='0' | ||
/> | ||
</div> | ||
); | ||
}, | ||
}); | ||
|
||
module.exports = WebPlayer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters