react-cosmos-native 6.0.0-canary.fe0c7d1.0 → 6.0.0
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,9 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { FixtureId, RendererConfig, UserModuleWrappers } from 'react-cosmos-core';
|
|
3
3
|
type Props = {
|
|
4
4
|
rendererConfig: RendererConfig;
|
|
5
5
|
moduleWrappers: UserModuleWrappers;
|
|
6
6
|
initialFixtureId?: FixtureId;
|
|
7
7
|
};
|
|
8
|
-
export declare function NativeFixtureLoader({ rendererConfig
|
|
8
|
+
export declare function NativeFixtureLoader({ rendererConfig, moduleWrappers, initialFixtureId, }: Props): React.JSX.Element;
|
|
9
9
|
export {};
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { ClientFixtureLoader } from 'react-cosmos-renderer/client';
|
|
3
3
|
import * as ReactNative from 'react-native';
|
|
4
|
-
import {
|
|
4
|
+
import { NativeRendererProvider } from './NativeRendererProvider.js';
|
|
5
5
|
const { View, Text, StyleSheet } = ReactNative;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const socketUrl = getSocketUrl(playgroundUrl);
|
|
10
|
-
return (React.createElement(FixtureConnect, { rendererId: rendererId, rendererConnect: createWebSocketsConnect(socketUrl), moduleWrappers: moduleWrappers, systemDecorators: [], initialFixtureId: initialFixtureId, renderMessage: renderMessage }));
|
|
6
|
+
export function NativeFixtureLoader({ rendererConfig, moduleWrappers, initialFixtureId, }) {
|
|
7
|
+
return (React.createElement(NativeRendererProvider, { rendererConfig: rendererConfig, initialFixtureId: initialFixtureId },
|
|
8
|
+
React.createElement(ClientFixtureLoader, { moduleWrappers: moduleWrappers, renderMessage: renderMessage })));
|
|
11
9
|
}
|
|
12
10
|
function renderMessage(msg) {
|
|
13
11
|
return (React.createElement(View, { style: styles.container },
|
|
14
|
-
React.createElement(Text,
|
|
12
|
+
React.createElement(Text, { style: styles.text }, msg)));
|
|
15
13
|
}
|
|
16
14
|
const styles = StyleSheet.create({
|
|
17
15
|
container: {
|
|
@@ -20,4 +18,8 @@ const styles = StyleSheet.create({
|
|
|
20
18
|
alignItems: 'center',
|
|
21
19
|
justifyContent: 'center',
|
|
22
20
|
},
|
|
21
|
+
text: {
|
|
22
|
+
fontSize: 24,
|
|
23
|
+
fontWeight: '300',
|
|
24
|
+
},
|
|
23
25
|
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { FixtureId, RendererConfig } from 'react-cosmos-core';
|
|
3
|
+
type Props = {
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
rendererConfig: RendererConfig;
|
|
6
|
+
initialFixtureId?: FixtureId | null;
|
|
7
|
+
};
|
|
8
|
+
export declare function NativeRendererProvider({ children, rendererConfig, initialFixtureId, }: Props): React.JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { createWebSocketsConnect } from 'react-cosmos-renderer';
|
|
3
|
+
import { StatefulRendererProvider } from 'react-cosmos-renderer/client';
|
|
4
|
+
import { DevSettings } from 'react-native';
|
|
5
|
+
import { getSocketUrl } from './getSocketUrl.js';
|
|
6
|
+
export function NativeRendererProvider({ children, rendererConfig, initialFixtureId = null, }) {
|
|
7
|
+
const rendererConnect = React.useMemo(() => createWebSocketsConnect(getSocketUrl(rendererConfig.playgroundUrl)), [rendererConfig.playgroundUrl]);
|
|
8
|
+
return (React.createElement(StatefulRendererProvider
|
|
9
|
+
// TODO: Generate unique ID per device
|
|
10
|
+
, {
|
|
11
|
+
// TODO: Generate unique ID per device
|
|
12
|
+
rendererId: "native-renderer", rendererConnect: rendererConnect, locked: false, selectedFixtureId: initialFixtureId, reloadRenderer: reloadRenderer }, children));
|
|
13
|
+
}
|
|
14
|
+
function reloadRenderer() {
|
|
15
|
+
DevSettings.reload();
|
|
16
|
+
}
|
package/dist/getSocketUrl.js
CHANGED
|
@@ -4,8 +4,10 @@ export function getSocketUrl(playgroundUrl) {
|
|
|
4
4
|
// The URL module isn't implemented fully in React Native and I don't want to
|
|
5
5
|
// bring in another dependency just for this.
|
|
6
6
|
const scriptURL = NativeModules.SourceCode.scriptURL;
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
7
|
+
// https://stackoverflow.com/a/27755/1332513
|
|
8
|
+
const urlRegex = /^(.*:)\/\/([A-Za-z0-9\-\.]+)(:[0-9]+)?(.*)$/;
|
|
9
|
+
const [, _protocol, host] = scriptURL.match(urlRegex) || [];
|
|
10
|
+
const [_url, protocol, _host, port = ':80'] = playgroundUrl.match(urlRegex) || [];
|
|
11
|
+
const wsProtocol = protocol === 'https:' ? 'wss' : 'ws';
|
|
12
|
+
return `${wsProtocol}://${host}${port}`;
|
|
11
13
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-cosmos-native",
|
|
3
|
-
"version": "6.0.0
|
|
3
|
+
"version": "6.0.0",
|
|
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
|
|
10
|
+
"react-cosmos-core": "^6.0.0",
|
|
11
|
+
"react-cosmos-renderer": "^6.0.0"
|
|
11
12
|
},
|
|
12
|
-
"gitHead": "
|
|
13
|
+
"gitHead": "db4fd8fd917598f1f16d4c291be76217436422ee"
|
|
13
14
|
}
|