Skip to content

Commit

Permalink
Add documentation URL in examples (#164)
Browse files Browse the repository at this point in the history
* Add documentation URL
  • Loading branch information
anku255 authored Jul 29, 2020
1 parent 6a58b86 commit 81d0199
Show file tree
Hide file tree
Showing 32 changed files with 62 additions and 11 deletions.
32 changes: 25 additions & 7 deletions packages/RNTester/js/components/ExamplePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@

import * as React from 'react';
import {
Alert,
ScrollView,
StyleSheet,
View,
Text,
Dimensions,
Image,
TouchableOpacity,
} from 'react-native';
import openURLInBrowser from 'react-native/Libraries/Core/Devtools/openURLInBrowser';

import HeadingText from './HeadingText';
import Background from './Background';
Expand All @@ -29,6 +32,7 @@ type Props = $ReadOnly<{|
description?: ?string,
ios?: ?boolean,
android?: ?boolean,
documentationURL?: ?string,
|}>;

const ScreenHeight = Dimensions.get('window').height;
Expand All @@ -39,24 +43,33 @@ export default function ExamplePage(props: Props): React.Node {

const description = props.description ?? '';
const androidImage = props.android ? (
<Image
style={{height: 35, width: 30, margin: 2}}
source={imagePaths.android}
/>
<Image style={styles.platformIcon} source={imagePaths.android} />
) : null;

const appleImage = props.ios ? (
<Image style={{height: 35, width: 30, margin: 2}} source={imagePaths.ios} />
<Image style={styles.platformIcon} source={imagePaths.ios} />
) : null;

const docsImage = <Image source={imagePaths.docs} />;
const DoucumentationURL = ({url}) => (
<View>
<TouchableOpacity
onPress={() => {
if (!url) {
return Alert.alert('Error!', 'Documentation URL is not available.');
}
openURLInBrowser(url);
}}>
<Image source={imagePaths.docs} />
</TouchableOpacity>
</View>
);

return (
<React.Fragment>
<View style={styles.titleView}>
<View style={styles.titleContainer}>
{title}
{docsImage}
<DoucumentationURL url={props.documentationURL} />
</View>
<View style={styles.iconContainer}>
{appleImage}
Expand Down Expand Up @@ -119,6 +132,11 @@ const styles = StyleSheet.create({
right: 0,
paddingBottom: 10,
},
platformIcon: {
height: 35,
width: 30,
margin: 2,
},
description: {
paddingHorizontal: 20,
},
Expand Down
11 changes: 7 additions & 4 deletions packages/RNTester/js/components/RNTesterExampleContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
'use strict';

const React = require('react');
const {Platform, Text} = require('react-native');
const {Platform} = require('react-native');
const RNTesterBlock = require('./RNTesterBlock');
const RNTesterExampleFilter = require('./RNTesterExampleFilter');

Expand Down Expand Up @@ -48,7 +48,8 @@ class RNTesterExampleContainer extends React.Component {
title={module.title}
description={module.description}
android={module.android}
ios={module.ios}>
ios={module.ios}
documentationURL={module.documentationURL}>
{module.examples[0].render()}
</ExamplePage>
);
Expand All @@ -59,7 +60,8 @@ class RNTesterExampleContainer extends React.Component {
title={module.title}
description={module.description}
android={module.android}
ios={module.ios}>
ios={module.ios}
documentationURL={module.documentationURL}>
{module.examples[0].render()}
</ExamplePage>
);
Expand All @@ -80,7 +82,8 @@ class RNTesterExampleContainer extends React.Component {
title={module.title}
description={module.description}
android={module.android}
ios={module.ios}>
ios={module.ios}
documentationURL={module.documentationURL}>
<RNTesterExampleFilter
testID="example_search"
sections={sections}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,7 @@ class AnnounceForAccessibility extends React.Component<{}> {

exports.title = 'Accessibility';
exports.description = 'Examples of using Accessibility APIs.';
exports.documentationURL = 'https://reactnative.dev/docs/accessibilityinfo';
exports.examples = [
{
title: 'Accessibility elements',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ exports.displayName = (undefined: ?string);
exports.framework = 'React';
exports.title = '<ActivityIndicator>';
exports.description = 'Animated loading indicators.';
exports.documentationURL = 'https://reactnative.dev/docs/activityindicator';

exports.examples = [
{
Expand Down
1 change: 1 addition & 0 deletions packages/RNTester/js/examples/Animated/AnimatedExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ exports.title = 'Animated - Examples';
exports.description = ('Animated provides a powerful ' +
'and easy-to-use API for building modern, ' +
'interactive user experiences.': string);
exports.documentationURL = 'https://reactnative.dev/docs/animated';

exports.examples = [
{
Expand Down
1 change: 1 addition & 0 deletions packages/RNTester/js/examples/AppState/AppStateExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class AppStateSubscription extends React.Component<

exports.title = 'AppState';
exports.description = 'app background status';
exports.documentationURL = 'https://reactnative.dev/docs/appstate';
exports.examples = [
{
title: 'AppState.currentState',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const ThemedText = props => (

exports.title = 'Appearance';
exports.description = 'Light and dark user interface examples.';
exports.documentationURL = 'https://reactnative.dev/docs/appearance';
exports.examples = [
{
title: 'useColorScheme hook',
Expand Down
1 change: 1 addition & 0 deletions packages/RNTester/js/examples/Button/ButtonExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ exports.displayName = 'ButtonExample';
exports.framework = 'React';
exports.title = '<Button>';
exports.description = 'Simple React Native button component.';
exports.documentationURL = 'https://reactnative.dev/docs/button';

exports.examples = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {Alert, Button, DevSettings} from 'react-native';

exports.title = 'DevSettings';
exports.description = 'Customize the development settings';
exports.documentationURL = 'https://reactnative.dev/docs/devsettings';
exports.examples = [
{
title: 'Add dev menu item',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class DimensionsSubscription extends React.Component<

exports.title = 'Dimensions';
exports.description = 'Dimensions of the viewport';
exports.documentationURL = 'https://reactnative.dev/docs/dimensions';
exports.examples = [
{
title: 'useWindowDimensions hook',
Expand Down
1 change: 1 addition & 0 deletions packages/RNTester/js/examples/FlatList/FlatListExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ const styles = StyleSheet.create({
exports.title = '<FlatList>';
exports.description = 'Performant, scrollable list of data.';
exports.simpleExampleContainer = true;
exports.documentationURL = 'https://reactnative.dev/docs/flatlist';
exports.examples = [
{
title: 'Simple list of items',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ const styles = StyleSheet.create({
exports.title = '<KeyboardAvoidingView>';
exports.description =
'Base component for views that automatically adjust their height or position to move out of the way of the keyboard.';
exports.documentationURL = 'https://reactnative.dev/docs/keyboardavoidingview';
exports.examples = [
{
title: 'Simple keyboard view',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ const styles = StyleSheet.create({

exports.title = 'Layout Animation';
exports.description = 'Layout animation';
exports.documentationURL = 'https://reactnative.dev/docs/layoutanimation';
exports.examples = [
{
title: 'Add and remove views',
Expand Down
1 change: 1 addition & 0 deletions packages/RNTester/js/examples/Linking/LinkingExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ const styles = StyleSheet.create({

exports.title = 'Linking';
exports.description = 'Shows how to use Linking to open URLs.';
exports.documentationURL = 'https://reactnative.dev/docs/linking';
exports.examples = [
{
title: 'Simple list of items',
Expand Down
1 change: 1 addition & 0 deletions packages/RNTester/js/examples/Modal/ModalExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ exports.displayName = (undefined: ?string);
exports.framework = 'React';
exports.title = '<Modal>';
exports.description = 'Component for presenting modal views.';
exports.documentationURL = 'https://reactnative.dev/docs/modal';

exports.examples = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ const styles = StyleSheet.create({
exports.title = 'PanResponder Sample';
exports.description =
'Shows the Use of PanResponder to provide basic gesture handling';
exports.documentationURL = 'https://reactnative.dev/docs/panresponder';
exports.simpleExampleContainer = true;
exports.examples = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ const styles = StyleSheet.create({
exports.title = 'PlatformColor';
exports.description =
'Examples that show how PlatformColors may be used in an app.';
exports.documentationURL = 'https://reactnative.dev/docs/platformcolor';
exports.examples = [
{
title: 'Platform Colors',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ const styles = StyleSheet.create({
exports.displayName = (undefined: ?string);
exports.description = 'Component for making views pressable.';
exports.title = '<Pressable>';
exports.documentationURL = 'https://reactnative.dev/docs/pressable';
exports.examples = [
{
title: 'Change content based on Press',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class RefreshControlExample extends React.Component {

exports.title = '<RefreshControl>';
exports.description = 'Adds pull-to-refresh support to a scrollview.';
exports.documentationURL = 'https://reactnative.dev/docs/refreshcontrol';
exports.simpleExampleContainer = true;
exports.examples = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ exports.framework = 'React';
exports.title = '<SafeAreaView>';
exports.description =
'SafeAreaView automatically applies paddings reflect the portion of the view that is not covered by other (special) ancestor views.';
exports.documentationURL = 'https://reactnative.dev/docs/safeareaview';
exports.examples = [
{
title: '<SafeAreaView> Example',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ exports.displayName = 'ScrollViewExample';
exports.title = '<ScrollView>';
exports.description =
'Component that enables scrolling through child components';
exports.documentationURL = 'https://reactnative.dev/docs/scrollview';
exports.examples = [
{
title: '<ScrollView>\n',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ const styles = StyleSheet.create({

exports.title = '<SectionList>';
exports.description = 'Performant, scrollable list of data.';
exports.documentationURL = 'https://reactnative.dev/docs/sectionlist';
exports.examples = [
{
title: 'Simple scrollable list',
Expand Down
1 change: 1 addition & 0 deletions packages/RNTester/js/examples/Share/ShareExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ const styles = StyleSheet.create({
exports.framework = 'React';
exports.title = 'Share';
exports.description = 'Share data with other Apps.';
exports.documentationURL = 'https://reactnative.dev/docs/share';
exports.examples = [
{
title: 'Share Text Content',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ class ModalExample extends React.Component<{...}, $FlowFixMeState> {
exports.framework = 'React';
exports.title = '<StatusBar>';
exports.description = 'Component for controlling the status bar';
exports.documentationURL = 'https://reactnative.dev/docs/statusbar';
exports.examples = [
{
title: 'StatusBar hidden',
Expand Down
1 change: 1 addition & 0 deletions packages/RNTester/js/examples/Switch/SwitchExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ const ExampleSwitchBackgroundColor = () => {
exports.title = '<Switch>';
exports.displayName = 'SwitchExample';
exports.description = 'Native boolean input';
exports.documentationURL = 'https://reactnative.dev/docs/switch';
exports.examples = [
{
title: 'Basic Switch',
Expand Down
1 change: 1 addition & 0 deletions packages/RNTester/js/examples/Text/TextExample.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,7 @@ const styles = StyleSheet.create({
});
exports.title = '<Text>';
exports.description = 'Base component for rendering styled text.';
exports.documentationURL = 'https://reactnative.dev/docs/text';
exports.examples = [
{
title: 'Basic text',
Expand Down
1 change: 1 addition & 0 deletions packages/RNTester/js/examples/Text/TextExample.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ class TextWithCapBaseBox extends React.Component<*, *> {

exports.title = '<Text>';
exports.description = 'Base component for rendering styled text.';
exports.documentationURL = 'https://reactnative.dev/docs/text';
exports.displayName = 'TextExample';
exports.examples = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ const EventHandlerOnTextInput = () => {
exports.title = '<TextInput>';
exports.description =
'A foundational component for inputting text into the app via a keyboard.';
exports.documentationURL = 'https://reactnative.dev/docs/textinput';
exports.examples = ([
{
title: 'TextInput with autoFocus={true}',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ const styles = StyleSheet.create({

exports.displayName = (undefined: ?string);
exports.description = 'Touchable and onPress examples.';
exports.documentationURL = 'https://reactnative.dev/docs/touchablehighlight';
exports.title = '<Touchable*> and onPress';
exports.examples = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ const styles = StyleSheet.create({

exports.title = 'Transforms';
exports.description = 'View transforms';
exports.documentationURL = 'https://reactnative.dev/docs/transforms';
exports.examples = [
{
title: 'Perspective, Rotate, Animation',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const {
exports.framework = 'React';
exports.title = 'Vibration';
exports.description = 'Vibration API';
exports.documentationURL = 'https://reactnative.dev/docs/vibration';

let pattern, patternLiteral, patternDescription;
if (Platform.OS === 'android') {
Expand Down
1 change: 1 addition & 0 deletions packages/RNTester/js/examples/View/ViewExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const {
exports.title = '<View>';
exports.description = ('Basic building block of all UI, examples that ' +
'demonstrate some of the many styles available.': string);
exports.documentationURL = 'https://reactnative.dev/docs/view';

exports.displayName = 'ViewExample';
exports.examples = [
Expand Down

0 comments on commit 81d0199

Please sign in to comment.