Skip to content

[Docs] Add support for syntax highlighting for languages other than JS #14215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions docs/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ React Native also requires a recent version of the [Java SE Development Kit (JDK

Open an Administrator Command Prompt (right click Command Prompt and select "Run as Administrator"), then run the following commands:

```
```powershell
choco install nodejs.install
choco install python2
choco install jdk8
Expand Down Expand Up @@ -272,7 +272,7 @@ Node comes with npm, which lets you install the React Native command line interf

Run the following command in a Command Prompt or shell:

```
```powershell
npm install -g react-native-cli
```

Expand Down Expand Up @@ -430,7 +430,7 @@ Open the System pane under **System and Security** in the Control Panel, then cl

The SDK is installed, by default, at the following location:

```
```powershell
c:\Users\YOUR_USERNAME\AppData\Local\Android\Sdk
```

Expand Down Expand Up @@ -646,7 +646,6 @@ function displayTab(type, value) {
var container = document.getElementsByTagName('block')[0].parentNode;
container.className = 'display-' + type + '-' + value + ' ' +
container.className.replace(RegExp('display-' + type + '-[a-z]+ ?'), '');
console.log(container.className);
event && event.preventDefault();
}
</script>
53 changes: 28 additions & 25 deletions docs/IntegrationWithExistingApps.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ To ensure a smooth experience, create a new folder for your integrated React Nat

Go to the root directory for your project and create a new `package.json` file with the following contents:

```bash
```
{
"name": "MyReactNativeApp",
"version": "0.0.1",
Expand All @@ -156,7 +156,7 @@ Go to the root directory for your project and create a new `package.json` file w

Next, you will install the `react` and `react-native` packages. Open a terminal or command prompt, then navigate to the root directory for your project and type the following commands:

```bash
```
$ npm install --save react react-native
```

Expand All @@ -170,7 +170,7 @@ This will create a new `/node_modules` folder in your project's root directory.

We recommend installing CocoaPods using [Homebrew](http://brew.sh/).

```bash
```
$ brew install cocoapods
```

Expand Down Expand Up @@ -200,7 +200,7 @@ The list of supported `subspec`s is available in [`/node_modules/react-native/Re

You can specify which `subspec`s your app will depend on in a `Podfile` file. The easiest way to create a `Podfile` is by running the CocoaPods `init` command in the `/ios` subfolder of your project:

```bash
```
$ pod init
```

Expand Down Expand Up @@ -258,13 +258,13 @@ end

After you have created your `Podfile`, you are ready to install the React Native pod.

```bash
```
$ pod install
```

You should see output such as:

```bash
```
Analyzing dependencies
Fetching podspec for `React` from `../node_modules/react-native`
Downloading dependencies
Expand Down Expand Up @@ -299,7 +299,7 @@ First, create an empty `index.ios.js` file in the root of your React Native proj

In your `index.ios.js`, create your component. In our sample here, we will add simple `<Text>` component within a styled `<View>`

```js
```javascript
'use strict';

import React from 'react';
Expand Down Expand Up @@ -377,21 +377,21 @@ We will, for debugging purposes, log that the event handler was invoked. Then, w

First `import` the `RCTRootView` header.

```
```objectivec
#import <React/RCTRootView.h>
```

> The `initialProperties` are here for illustration purposes so we have some data for our high score screen. In our React Native component, we will use `this.props` to get access to that data.

```
```objectivec
- (IBAction)highScoreButtonPressed:(id)sender {
NSLog(@"High Score Button Pressed");
NSURL *jsCodeLocation = [NSURL
URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios"];
NSURL *jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios"];

RCTRootView *rootView =
[[RCTRootView alloc] initWithBundleURL : jsCodeLocation
moduleName : @"RNHighScores"
initialProperties :
[[RCTRootView alloc] initWithBundleURL: jsCodeLocation
moduleName: @"RNHighScores"
initialProperties:
@{
@"scores" : @[
@{
Expand All @@ -404,7 +404,7 @@ First `import` the `RCTRootView` header.
}
]
}
launchOptions : nil];
launchOptions: nil];
UIViewController *vc = [[UIViewController alloc] init];
vc.view = rootView;
[self presentViewController:vc animated:YES completion:nil];
Expand All @@ -417,13 +417,13 @@ First `import` the `RCTRootView` header.

First `import` the `React` library.

```
```javascript
import React
```

> The `initialProperties` are here for illustration purposes so we have some data for our high score screen. In our React Native component, we will use `this.props` to get access to that data.

```
```swift
@IBAction func highScoreButtonTapped(sender : UIButton) {
NSLog("Hello")
let jsCodeLocation = URL(string: "http://localhost:8081/index.ios.bundle?platform=ios")
Expand Down Expand Up @@ -494,15 +494,15 @@ Apple has blocked implicit cleartext HTTP resource loading. So we need to add th

To run your app, you need to first start the development server. To do this, simply run the following command in the root directory of your React Native project:

```bash
```
$ npm start
```

##### 3. Run the app

If you are using Xcode or your favorite editor, build and run your native iOS application as normal. Alternatively, you can run the app from the command line using:

```bash
```
# From the root of your project
$ react-native run-ios
```
Expand Down Expand Up @@ -593,7 +593,7 @@ First, create an empty `index.android.js` file in the root of your React Native

In your `index.android.js`, create your component. In our sample here, we will add simple `<Text>` component within a styled `<View>`:

```js
```javascript
'use strict';

import React from 'react';
Expand Down Expand Up @@ -692,11 +692,13 @@ public class MyReactActivity extends Activity implements DefaultHardwareBackBtnH
}
}
```

> If you are using a starter kit for React Native, replace the "HelloWorld" string with the one in your index.android.js file (it’s the first argument to the `AppRegistry.registerComponent()` method).

If you are using Android Studio, use `Alt + Enter` to add all missing imports in your MyReactActivity class. Be careful to use your package’s `BuildConfig` and not the one from the `...facebook...` package.

We need set the theme of `MyReactActivity` to `Theme.AppCompat.Light.NoActionBar` because some components rely on this theme.

```xml
<activity
android:name=".MyReactActivity"
Expand Down Expand Up @@ -776,7 +778,7 @@ You have now done all the basic steps to integrate React Native with your curren

To run your app, you need to first start the development server. To do this, simply run the following command in the root directory of your React Native project:

```bash
```
$ npm start
```

Expand All @@ -790,11 +792,13 @@ Once you reach your React-powered activity inside the app, it should load the Ja

### Creating a release build in Android Studio

You can use Android Studio to create your release builds too! It’s as easy as creating release builds of your previously-existing native Android app. There’s just one additional step, which you’ll have to do before every release build. You need to execute the following to create a React Native bundle, which’ll be included with your native Android app:
You can use Android Studio to create your release builds too! It’s as easy as creating release builds of your previously-existing native Android app. There’s just one additional step, which you’ll have to do before every release build. You need to execute the following to create a React Native bundle, which will be included with your native Android app:

$ react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/com/your-company-name/app-package-name/src/main/assets/index.android.bundle --assets-dest android/com/your-company-name/app-package-name/src/main/res/
```
$ react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/com/your-company-name/app-package-name/src/main/assets/index.android.bundle --assets-dest android/com/your-company-name/app-package-name/src/main/res/
```

Don’t forget to replace the paths with correct ones and create the assets folder if it doesn’t exist!
> Don’t forget to replace the paths with correct ones and create the assets folder if it doesn’t exist.

Now just create a release build of your native app from within Android Studio as usual and you should be good to go!

Expand All @@ -809,7 +813,6 @@ function displayTab(type, value) {
var container = document.getElementsByTagName('block')[0].parentNode;
container.className = 'display-' + type + '-' + value + ' ' +
container.className.replace(RegExp('display-' + type + '-[a-z]+ ?'), '');
console.log(container.className);
event && event.preventDefault();
}
</script>
16 changes: 8 additions & 8 deletions docs/NativeComponentsIOS.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Vending a view is simple:
- Add the `RCT_EXPORT_MODULE()` marker macro.
- Implement the `-(UIView *)view` method.

```objective-c
```objectivec
// RNTMapManager.m
#import <MapKit/MapKit.h>

Expand Down Expand Up @@ -66,7 +66,7 @@ This is now a fully-functioning native map view component in JavaScript, complet

The first thing we can do to make this component more usable is to bridge over some native properties. Let's say we want to be able to disable pitch control and specify the visible region. Disabling pitch is a simple boolean, so we add this one line:

```objective-c
```objectivec
// RNTMapManager.m
RCT_EXPORT_VIEW_PROPERTY(pitchEnabled, BOOL)
```
Expand Down Expand Up @@ -113,7 +113,7 @@ Now we have a nicely documented wrapper component that is easy to work with. No

Next, let's add the more complex `region` prop. We start by adding the native code:

```objective-c
```objectivec
// RNTMapManager.m
RCT_CUSTOM_VIEW_PROPERTY(region, MKCoordinateRegion, RNTMap)
{
Expand All @@ -125,7 +125,7 @@ Ok, this is more complicated than the simple `BOOL` case we had before. Now we

You could write any conversion function you want for your view - here is the implementation for `MKCoordinateRegion` via two categories on `RCTConvert`:

```objective-c
```objectivec
@implementation RCTConvert(CoreLocation)

RCT_CONVERTER(CLLocationDegrees, CLLocationDegrees, doubleValue);
Expand Down Expand Up @@ -229,7 +229,7 @@ var RCTSwitch = requireNativeComponent('RCTSwitch', Switch, {

So now we have a native map component that we can control easily from JS, but how do we deal with events from the user, like pinch-zooms or panning to change the visible region? The key is to declare an event handler property on `RNTMapManager`, make it a delegate for all the views it vends, and forward events to JS by calling the event handler block from the native view. This looks like so (simplified from the full implementation):

```objective-c
```objectivec
// RNTMap.h

#import <MapKit/MapKit.h>
Expand All @@ -243,7 +243,7 @@ So now we have a native map component that we can control easily from JS, but ho
@end
```

```objective-c
```objectivec
// RNTMap.m

#import "RNTMap.h"
Expand All @@ -253,7 +253,7 @@ So now we have a native map component that we can control easily from JS, but ho
@end
```

```objective-c
```objectivec
// RNTMapManager.m

#import "RNTMapManager.h"
Expand Down Expand Up @@ -383,7 +383,7 @@ var styles = StyleSheet.create({

The `RCTDatePickerIOSConsts` constants are exported from native by grabbing the actual frame of the native component like so:

```objective-c
```objectivec
// RCTDatePickerManager.m

- (NSDictionary *)constantsToExport
Expand Down
Loading