react-cosmos-native 6.0.0-alpha.0 → 6.0.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { createWebSocketsConnect, FixtureLoader, } from 'react-cosmos-core';
|
|
3
3
|
import * as ReactNative from 'react-native';
|
|
4
|
-
|
|
4
|
+
import { getSocketUrl } from './getSocketUrl.js';
|
|
5
|
+
const { View, Text, StyleSheet } = ReactNative;
|
|
5
6
|
// TODO: Generate unique ID per device
|
|
6
7
|
const rendererId = 'native-renderer';
|
|
7
8
|
export function NativeFixtureLoader({ rendererConfig: { playgroundUrl }, fixtures, decorators, initialFixtureId, }) {
|
|
8
9
|
const socketUrl = getSocketUrl(playgroundUrl);
|
|
9
10
|
return (React.createElement(FixtureLoader, { rendererId: rendererId, rendererConnect: createWebSocketsConnect(socketUrl), fixtures: fixtures, initialFixtureId: initialFixtureId, systemDecorators: [], userDecorators: decorators, renderMessage: renderMessage }));
|
|
10
11
|
}
|
|
11
|
-
function getSocketUrl(playgroundUrl) {
|
|
12
|
-
const { hostname } = new URL(NativeModules.SourceCode.scriptURL);
|
|
13
|
-
const { port } = new URL(playgroundUrl);
|
|
14
|
-
return `ws://${hostname}:${port}`;
|
|
15
|
-
}
|
|
16
12
|
function renderMessage({ msg }) {
|
|
17
13
|
return (React.createElement(View, { style: styles.container },
|
|
18
14
|
React.createElement(Text, null, msg)));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getSocketUrl(playgroundUrl: string): string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as ReactNative from 'react-native';
|
|
2
|
+
const { NativeModules } = ReactNative;
|
|
3
|
+
export function getSocketUrl(playgroundUrl) {
|
|
4
|
+
// The URL module isn't implemented fully in React Native and I don't want to
|
|
5
|
+
// bring in another dependency just for this.
|
|
6
|
+
const scriptURL = NativeModules.SourceCode.scriptURL;
|
|
7
|
+
const [, hostname] = scriptURL.match(/:\/\/(.+?)(:|\/)/);
|
|
8
|
+
const portMatch = playgroundUrl.match(/:(\d+)(\/|$)/);
|
|
9
|
+
const port = portMatch ? portMatch[1] : '80';
|
|
10
|
+
return `ws://${hostname}:${port}`;
|
|
11
|
+
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-cosmos-native",
|
|
3
|
-
"version": "6.0.0-alpha.
|
|
3
|
+
"version": "6.0.0-alpha.6",
|
|
4
4
|
"description": "React Cosmos Native",
|
|
5
5
|
"repository": "https://github.com/react-cosmos/react-cosmos/tree/main/packages/react-cosmos-native",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "./dist/index.js",
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"react-cosmos-core": "^6.0.0-alpha.
|
|
10
|
+
"react-cosmos-core": "^6.0.0-alpha.6"
|
|
11
11
|
},
|
|
12
|
-
"gitHead": "
|
|
12
|
+
"gitHead": "e901d3a46ee43a24b6279395e6718c9521088b60"
|
|
13
13
|
}
|