Skip to content

Commit

Permalink
chore: configure Metro to consume source directly (react-native-webvi…
Browse files Browse the repository at this point in the history
…ew#2395)

This will allow developers to modify the TypeScript code and see changes
without having to run `tsc --watch` separately.
  • Loading branch information
tido64 authored Mar 3, 2022
1 parent b1c48ce commit 5c49dbc
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 24 deletions.
1 change: 1 addition & 0 deletions metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ module.exports = {
projectRoot: path.join(__dirname, 'example'),
watchFolders: [__dirname],
resolver: {
resolverMainFields: ['main-internal', 'browser', 'main'],
blacklistRE: blockList,
blockList,
},
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "react-native-webview",
"description": "React Native WebView component for iOS, Android, macOS, and Windows",
"main": "index.js",
"main-internal": "src/index.ts",
"typings": "index.d.ts",
"author": "Jamon Holmgren <jamon@infinite.red>",
"contributors": [
Expand Down
5 changes: 1 addition & 4 deletions src/WebView.android.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from 'react';

import {
Image,
requireNativeComponent,
UIManager as NotTypedUIManager,
View,
NativeModules,
Expand All @@ -14,6 +13,7 @@ import BatchedBridge from 'react-native/Libraries/BatchedBridge/BatchedBridge';

import invariant from 'invariant';

import RNCWebView from "./WebViewNativeComponent.android";
import {
defaultOriginWhitelist,
createOnShouldStartLoadWithRequest,
Expand All @@ -37,9 +37,6 @@ import styles from './WebView.styles';

const UIManager = NotTypedUIManager as RNCWebViewUIManagerAndroid;

const RNCWebView = requireNativeComponent(
'RNCWebView',
) as typeof NativeWebViewAndroid;
const { resolveAssetSource } = Image;

/**
Expand Down
8 changes: 2 additions & 6 deletions src/WebView.ios.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import React from 'react';
import {
UIManager as NotTypedUIManager,
View,
requireNativeComponent,
NativeModules,
Image,
findNodeHandle,
ImageSourcePropType,
} from 'react-native';
import invariant from 'invariant';

import RNCWebView from "./WebViewNativeComponent.ios";
import {
defaultOriginWhitelist,
createOnShouldStartLoadWithRequest,
Expand Down Expand Up @@ -50,10 +50,6 @@ const processDecelerationRate = (

const RNCWebViewManager = NativeModules.RNCWebViewManager as ViewManager;

const RNCWebView: typeof NativeWebViewIOS = requireNativeComponent(
'RNCWebView',
);

class WebView extends React.Component<IOSWebViewProps, State> {
static defaultProps = {
javaScriptEnabled: true,
Expand Down Expand Up @@ -202,7 +198,7 @@ class WebView extends React.Component<IOSWebViewProps, State> {
} else {
console.warn('Encountered an error loading page', event.nativeEvent);
}

if (onLoadEnd) {
onLoadEnd(event);
}
Expand Down
8 changes: 2 additions & 6 deletions src/WebView.macos.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import React from 'react';
import {
UIManager as NotTypedUIManager,
View,
requireNativeComponent,
NativeModules,
Image,
findNodeHandle,
ImageSourcePropType,
} from 'react-native';
import invariant from 'invariant';

import RNCWebView from "./WebViewNativeComponent.ios";
import {
defaultOriginWhitelist,
createOnShouldStartLoadWithRequest,
Expand Down Expand Up @@ -38,10 +38,6 @@ const { resolveAssetSource } = Image;

const RNCWebViewManager = NativeModules.RNCWebViewManager as ViewManager;

const RNCWebView: typeof NativeWebViewMacOS = requireNativeComponent(
'RNCWebView',
);

class WebView extends React.Component<MacOSWebViewProps, State> {
static defaultProps = {
javaScriptEnabled: true,
Expand Down Expand Up @@ -189,7 +185,7 @@ class WebView extends React.Component<MacOSWebViewProps, State> {
} else {
console.warn('Encountered an error loading page', event.nativeEvent);
}

if (onLoadEnd) {
onLoadEnd(event);
}
Expand Down
11 changes: 3 additions & 8 deletions src/WebView.windows.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ import React from 'react';
import {
UIManager as NotTypedUIManager,
View,
requireNativeComponent,
StyleSheet,
Image,
ImageSourcePropType,
findNodeHandle,
} from 'react-native';
import {
createOnShouldStartLoadWithRequest,
} from './WebViewShared';
import RCTWebView from "./WebViewNativeComponent.windows";
import { createOnShouldStartLoadWithRequest } from './WebViewShared';
import {
NativeWebViewWindows,
WebViewSharedProps,
Expand All @@ -37,9 +35,6 @@ import {

const UIManager = NotTypedUIManager as RNCWebViewUIManagerWindows;
const { resolveAssetSource } = Image;
const RCTWebView: typeof NativeWebViewWindows = requireNativeComponent(
'RCTWebView',
);

const styles = StyleSheet.create({
container: {
Expand Down Expand Up @@ -104,7 +99,7 @@ export default class WebView extends React.Component<WebViewSharedProps, State>
);
}

postMessage = (data: string) => {
postMessage = (data: string) => {
const message = this.getInjectableJSMessage(data);
UIManager.dispatchViewManagerCommand(
this.getWebViewHandle(),
Expand Down
8 changes: 8 additions & 0 deletions src/WebViewNativeComponent.android.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { requireNativeComponent } from "react-native";
import type { NativeWebViewAndroid } from "./WebViewTypes";

const RNCWebView: typeof NativeWebViewAndroid = requireNativeComponent(
'RNCWebView',
);

export default RNCWebView;
8 changes: 8 additions & 0 deletions src/WebViewNativeComponent.ios.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { requireNativeComponent } from "react-native";
import type { NativeWebViewIOS } from "./WebViewTypes";

const RNCWebView: typeof NativeWebViewIOS = requireNativeComponent(
'RNCWebView',
);

export default RNCWebView;
8 changes: 8 additions & 0 deletions src/WebViewNativeComponent.macos.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { requireNativeComponent } from "react-native";
import type { NativeWebViewMacOS } from "./WebViewTypes";

const RNCWebView: typeof NativeWebViewMacOS = requireNativeComponent(
'RNCWebView',
);

export default RNCWebView;
8 changes: 8 additions & 0 deletions src/WebViewNativeComponent.windows.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { requireNativeComponent } from "react-native";
import type { NativeWebViewWindows } from "./WebViewTypes";

const RCTWebView: typeof NativeWebViewWindows = requireNativeComponent(
'RCTWebView',
);

export default RCTWebView;
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import WebView from './WebView';

export { WebView };
export default WebView;

0 comments on commit 5c49dbc

Please sign in to comment.