GeezerVison is showing github.com — Convert React Native builds to named exports (#18136) · react/react@3e809bf
File treeExpand file treeCollapse file tree Open diff view settings packages/react-native-renderer
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/react-native-renderer/fabric.js +6-6Lines changed: 6 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 7 | 7 | * @flow | 8 | 8 | */ | 9 | 9 |
| 10 | | -'use strict'; | | 10 | +import type {ReactFabricType} from './src/ReactNativeTypes'; | | 11 | +import * as ReactFabric from './src/ReactFabric'; | | 12 | +// Assert that the exports line up with the type we're going to expose. | | 13 | +// eslint-disable-next-line no-unused-expressions | | 14 | +(ReactFabric: ReactFabricType); | 11 | 15 |
| 12 | | -const ReactFabric = require('./src/ReactFabric'); | 13 | | - | 14 | | -// TODO: decide on the top-level export form. | 15 | | -// This is hacky but makes it work with both Rollup and Jest. | 16 | | -module.exports = ReactFabric.default || ReactFabric; | | 16 | +export * from './src/ReactFabric'; |
Collapse file Copy file name to clipboardExpand all lines: packages/react-native-renderer/index.js +6-6Lines changed: 6 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 7 | 7 | * @flow | 8 | 8 | */ | 9 | 9 |
| 10 | | -'use strict'; | | 10 | +import type {ReactNativeType} from './src/ReactNativeTypes'; | | 11 | +import * as ReactNative from './src/ReactNativeRenderer'; | | 12 | +// Assert that the exports line up with the type we're going to expose. | | 13 | +// eslint-disable-next-line no-unused-expressions | | 14 | +(ReactNative: ReactNativeType); | 11 | 15 |
| 12 | | -const ReactNativeRenderer = require('./src/ReactNativeRenderer'); | 13 | | - | 14 | | -// TODO: decide on the top-level export form. | 15 | | -// This is hacky but makes it work with both Rollup and Jest. | 16 | | -module.exports = ReactNativeRenderer.default || ReactNativeRenderer; | | 16 | +export * from './src/ReactNativeRenderer'; |
Collapse file Copy file name to clipboardExpand all lines: packages/react-native-renderer/src/ReactFabric.js +71-66Lines changed: 71 additions & 66 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 7 | 7 | * @flow | 8 | 8 | */ | 9 | 9 |
| 10 | | -import type {ReactFabricType, HostComponent} from './ReactNativeTypes'; | | 10 | +import type {HostComponent} from './ReactNativeTypes'; | 11 | 11 | import type {ReactNodeList} from 'shared/ReactTypes'; | 12 | 12 | import type {ElementRef} from 'react'; | 13 | 13 |
| @@ -26,7 +26,7 @@ import { | 26 | 26 | getPublicRootInstance, | 27 | 27 | } from 'react-reconciler/inline.fabric'; | 28 | 28 |
| 29 | | -import {createPortal} from 'shared/ReactPortal'; | | 29 | +import {createPortal as createPortalImpl} from 'shared/ReactPortal'; | 30 | 30 | import {setBatchingImplementation} from 'legacy-events/ReactGenericBatching'; | 31 | 31 | import ReactVersion from 'shared/ReactVersion'; | 32 | 32 |
| @@ -144,6 +144,69 @@ function findNodeHandle(componentOrHandle: any): ?number { | 144 | 144 | return hostInstance._nativeTag; | 145 | 145 | } | 146 | 146 |
| | 147 | +function dispatchCommand(handle: any, command: string, args: Array<any>) { | | 148 | + if (handle._nativeTag == null) { | | 149 | + if (__DEV__) { | | 150 | + console.error( | | 151 | + "dispatchCommand was called with a ref that isn't a " + | | 152 | + 'native component. Use React.forwardRef to get access to the underlying native component', | | 153 | + ); | | 154 | + } | | 155 | + | | 156 | + return; | | 157 | + } | | 158 | + | | 159 | + if (handle._internalInstanceHandle) { | | 160 | + nativeFabricUIManager.dispatchCommand( | | 161 | + handle._internalInstanceHandle.stateNode.node, | | 162 | + command, | | 163 | + args, | | 164 | + ); | | 165 | + } else { | | 166 | + UIManager.dispatchViewManagerCommand(handle._nativeTag, command, args); | | 167 | + } | | 168 | +} | | 169 | + | | 170 | +function render( | | 171 | + element: React$Element<any>, | | 172 | + containerTag: any, | | 173 | + callback: ?Function, | | 174 | +) { | | 175 | + let root = roots.get(containerTag); | | 176 | + | | 177 | + if (!root) { | | 178 | + // TODO (bvaughn): If we decide to keep the wrapper component, | | 179 | + // We could create a wrapper for containerTag as well to reduce special casing. | | 180 | + root = createContainer(containerTag, LegacyRoot, false, null); | | 181 | + roots.set(containerTag, root); | | 182 | + } | | 183 | + updateContainer(element, root, null, callback); | | 184 | + | | 185 | + return getPublicRootInstance(root); | | 186 | +} | | 187 | + | | 188 | +function unmountComponentAtNode(containerTag: number) { | | 189 | + this.stopSurface(containerTag); | | 190 | +} | | 191 | + | | 192 | +function stopSurface(containerTag: number) { | | 193 | + const root = roots.get(containerTag); | | 194 | + if (root) { | | 195 | + // TODO: Is it safe to reset this now or should I wait since this unmount could be deferred? | | 196 | + updateContainer(null, root, null, () => { | | 197 | + roots.delete(containerTag); | | 198 | + }); | | 199 | + } | | 200 | +} | | 201 | + | | 202 | +function createPortal( | | 203 | + children: ReactNodeList, | | 204 | + containerTag: number, | | 205 | + key: ?string = null, | | 206 | +) { | | 207 | + return createPortalImpl(children, containerTag, null, key); | | 208 | +} | | 209 | + | 147 | 210 | setBatchingImplementation( | 148 | 211 | batchedUpdatesImpl, | 149 | 212 | discreteUpdates, | @@ -153,74 +216,18 @@ setBatchingImplementation( | 153 | 216 |
| 154 | 217 | const roots = new Map(); | 155 | 218 |
| 156 | | -const ReactFabric: ReactFabricType = { | | 219 | +export { | 157 | 220 | // This is needed for implementation details of TouchableNativeFeedback | 158 | 221 | // Remove this once TouchableNativeFeedback doesn't use cloneElement | 159 | 222 | findHostInstance_DEPRECATED, | 160 | 223 | findNodeHandle, | 161 | | - | 162 | | - dispatchCommand(handle: any, command: string, args: Array<any>) { | 163 | | - if (handle._nativeTag == null) { | 164 | | - if (__DEV__) { | 165 | | - console.error( | 166 | | - "dispatchCommand was called with a ref that isn't a " + | 167 | | - 'native component. Use React.forwardRef to get access to the underlying native component', | 168 | | - ); | 169 | | - } | 170 | | - | 171 | | - return; | 172 | | - } | 173 | | - | 174 | | - if (handle._internalInstanceHandle) { | 175 | | - nativeFabricUIManager.dispatchCommand( | 176 | | - handle._internalInstanceHandle.stateNode.node, | 177 | | - command, | 178 | | - args, | 179 | | - ); | 180 | | - } else { | 181 | | - UIManager.dispatchViewManagerCommand(handle._nativeTag, command, args); | 182 | | - } | 183 | | - }, | 184 | | - | 185 | | - render(element: React$Element<any>, containerTag: any, callback: ?Function) { | 186 | | - let root = roots.get(containerTag); | 187 | | - | 188 | | - if (!root) { | 189 | | - // TODO (bvaughn): If we decide to keep the wrapper component, | 190 | | - // We could create a wrapper for containerTag as well to reduce special casing. | 191 | | - root = createContainer(containerTag, LegacyRoot, false, null); | 192 | | - roots.set(containerTag, root); | 193 | | - } | 194 | | - updateContainer(element, root, null, callback); | 195 | | - | 196 | | - return getPublicRootInstance(root); | 197 | | - }, | 198 | | - | | 224 | + dispatchCommand, | | 225 | + render, | 199 | 226 | // Deprecated - this function is being renamed to stopSurface, use that instead. | 200 | 227 | // TODO (T47576999): Delete this once it's no longer called from native code. | 201 | | - unmountComponentAtNode(containerTag: number) { | 202 | | - this.stopSurface(containerTag); | 203 | | - }, | 204 | | - | 205 | | - stopSurface(containerTag: number) { | 206 | | - const root = roots.get(containerTag); | 207 | | - if (root) { | 208 | | - // TODO: Is it safe to reset this now or should I wait since this unmount could be deferred? | 209 | | - updateContainer(null, root, null, () => { | 210 | | - roots.delete(containerTag); | 211 | | - }); | 212 | | - } | 213 | | - }, | 214 | | - | 215 | | - createPortal( | 216 | | - children: ReactNodeList, | 217 | | - containerTag: number, | 218 | | - key: ?string = null, | 219 | | - ) { | 220 | | - return createPortal(children, containerTag, null, key); | 221 | | - }, | 222 | | - | 223 | | - __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: {}, | | 228 | + unmountComponentAtNode, | | 229 | + stopSurface, | | 230 | + createPortal, | 224 | 231 | }; | 225 | 232 |
| 226 | 233 | injectIntoDevTools({ | @@ -230,5 +237,3 @@ injectIntoDevTools({ | 230 | 237 | version: ReactVersion, | 231 | 238 | rendererPackageName: 'react-native-renderer', | 232 | 239 | }); | 233 | | - | 234 | | -export default ReactFabric; | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-native-renderer/src/ReactNativeRenderer.js +79-72Lines changed: 79 additions & 72 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 7 | 7 | * @flow | 8 | 8 | */ | 9 | 9 |
| 10 | | -import type {ReactNativeType, HostComponent} from './ReactNativeTypes'; | | 10 | +import type {HostComponent} from './ReactNativeTypes'; | 11 | 11 | import type {ReactNodeList} from 'shared/ReactTypes'; | 12 | 12 |
| 13 | 13 | import './ReactNativeInjection'; | @@ -26,7 +26,7 @@ import { | 26 | 26 | } from 'react-reconciler/inline.native'; | 27 | 27 | // TODO: direct imports like some-package/src/* are bad. Fix me. | 28 | 28 | import {getStackByFiberInDevAndProd} from 'react-reconciler/src/ReactCurrentFiber'; | 29 | | -import {createPortal} from 'shared/ReactPortal'; | | 29 | +import {createPortal as createPortalImpl} from 'shared/ReactPortal'; | 30 | 30 | import { | 31 | 31 | setBatchingImplementation, | 32 | 32 | batchedUpdates, | @@ -144,6 +144,71 @@ function findNodeHandle(componentOrHandle: any): ?number { | 144 | 144 | return hostInstance._nativeTag; | 145 | 145 | } | 146 | 146 |
| | 147 | +function dispatchCommand(handle: any, command: string, args: Array<any>) { | | 148 | + if (handle._nativeTag == null) { | | 149 | + if (__DEV__) { | | 150 | + console.error( | | 151 | + "dispatchCommand was called with a ref that isn't a " + | | 152 | + 'native component. Use React.forwardRef to get access to the underlying native component', | | 153 | + ); | | 154 | + } | | 155 | + return; | | 156 | + } | | 157 | + | | 158 | + if (handle._internalInstanceHandle) { | | 159 | + nativeFabricUIManager.dispatchCommand( | | 160 | + handle._internalInstanceHandle.stateNode.node, | | 161 | + command, | | 162 | + args, | | 163 | + ); | | 164 | + } else { | | 165 | + UIManager.dispatchViewManagerCommand(handle._nativeTag, command, args); | | 166 | + } | | 167 | +} | | 168 | + | | 169 | +function render( | | 170 | + element: React$Element<any>, | | 171 | + containerTag: any, | | 172 | + callback: ?Function, | | 173 | +) { | | 174 | + let root = roots.get(containerTag); | | 175 | + | | 176 | + if (!root) { | | 177 | + // TODO (bvaughn): If we decide to keep the wrapper component, | | 178 | + // We could create a wrapper for containerTag as well to reduce special casing. | | 179 | + root = createContainer(containerTag, LegacyRoot, false, null); | | 180 | + roots.set(containerTag, root); | | 181 | + } | | 182 | + updateContainer(element, root, null, callback); | | 183 | + | | 184 | + return getPublicRootInstance(root); | | 185 | +} | | 186 | + | | 187 | +function unmountComponentAtNode(containerTag: number) { | | 188 | + const root = roots.get(containerTag); | | 189 | + if (root) { | | 190 | + // TODO: Is it safe to reset this now or should I wait since this unmount could be deferred? | | 191 | + updateContainer(null, root, null, () => { | | 192 | + roots.delete(containerTag); | | 193 | + }); | | 194 | + } | | 195 | +} | | 196 | + | | 197 | +function unmountComponentAtNodeAndRemoveContainer(containerTag: number) { | | 198 | + unmountComponentAtNode(containerTag); | | 199 | + | | 200 | + // Call back into native to remove all of the subviews from this container | | 201 | + UIManager.removeRootView(containerTag); | | 202 | +} | | 203 | + | | 204 | +function createPortal( | | 205 | + children: ReactNodeList, | | 206 | + containerTag: number, | | 207 | + key: ?string = null, | | 208 | +) { | | 209 | + return createPortalImpl(children, containerTag, null, key); | | 210 | +} | | 211 | + | 147 | 212 | setBatchingImplementation( | 148 | 213 | batchedUpdatesImpl, | 149 | 214 | discreteUpdates, | @@ -161,78 +226,22 @@ function computeComponentStackForErrorReporting(reactTag: number): string { | 161 | 226 |
| 162 | 227 | const roots = new Map(); | 163 | 228 |
| 164 | | -const ReactNativeRenderer: ReactNativeType = { | | 229 | +const Internals = { | | 230 | + computeComponentStackForErrorReporting, | | 231 | +}; | | 232 | + | | 233 | +export { | 165 | 234 | // This is needed for implementation details of TouchableNativeFeedback | 166 | 235 | // Remove this once TouchableNativeFeedback doesn't use cloneElement | 167 | 236 | findHostInstance_DEPRECATED, | 168 | 237 | findNodeHandle, | 169 | | - | 170 | | - dispatchCommand(handle: any, command: string, args: Array<any>) { | 171 | | - if (handle._nativeTag == null) { | 172 | | - if (__DEV__) { | 173 | | - console.error( | 174 | | - "dispatchCommand was called with a ref that isn't a " + | 175 | | - 'native component. Use React.forwardRef to get access to the underlying native component', | 176 | | - ); | 177 | | - } | 178 | | - return; | 179 | | - } | 180 | | - | 181 | | - if (handle._internalInstanceHandle) { | 182 | | - nativeFabricUIManager.dispatchCommand( | 183 | | - handle._internalInstanceHandle.stateNode.node, | 184 | | - command, | 185 | | - args, | 186 | | - ); | 187 | | - } else { | 188 | | - UIManager.dispatchViewManagerCommand(handle._nativeTag, command, args); | 189 | | - } | 190 | | - }, | 191 | | - | 192 | | - render(element: React$Element<any>, containerTag: any, callback: ?Function) { | 193 | | - let root = roots.get(containerTag); | 194 | | - | 195 | | - if (!root) { | 196 | | - // TODO (bvaughn): If we decide to keep the wrapper component, | 197 | | - // We could create a wrapper for containerTag as well to reduce special casing. | 198 | | - root = createContainer(containerTag, LegacyRoot, false, null); | 199 | | - roots.set(containerTag, root); | 200 | | - } | 201 | | - updateContainer(element, root, null, callback); | 202 | | - | 203 | | - return getPublicRootInstance(root); | 204 | | - }, | 205 | | - | 206 | | - unmountComponentAtNode(containerTag: number) { | 207 | | - const root = roots.get(containerTag); | 208 | | - if (root) { | 209 | | - // TODO: Is it safe to reset this now or should I wait since this unmount could be deferred? | 210 | | - updateContainer(null, root, null, () => { | 211 | | - roots.delete(containerTag); | 212 | | - }); | 213 | | - } | 214 | | - }, | 215 | | - | 216 | | - unmountComponentAtNodeAndRemoveContainer(containerTag: number) { | 217 | | - ReactNativeRenderer.unmountComponentAtNode(containerTag); | 218 | | - | 219 | | - // Call back into native to remove all of the subviews from this container | 220 | | - UIManager.removeRootView(containerTag); | 221 | | - }, | 222 | | - | 223 | | - createPortal( | 224 | | - children: ReactNodeList, | 225 | | - containerTag: number, | 226 | | - key: ?string = null, | 227 | | - ) { | 228 | | - return createPortal(children, containerTag, null, key); | 229 | | - }, | 230 | | - | 231 | | - unstable_batchedUpdates: batchedUpdates, | 232 | | - | 233 | | - __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: { | 234 | | - computeComponentStackForErrorReporting, | 235 | | - }, | | 238 | + dispatchCommand, | | 239 | + render, | | 240 | + unmountComponentAtNode, | | 241 | + unmountComponentAtNodeAndRemoveContainer, | | 242 | + createPortal, | | 243 | + batchedUpdates as unstable_batchedUpdates, | | 244 | + Internals as __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED, | 236 | 245 | }; | 237 | 246 |
| 238 | 247 | injectIntoDevTools({ | @@ -242,5 +251,3 @@ injectIntoDevTools({ | 242 | 251 | version: ReactVersion, | 243 | 252 | rendererPackageName: 'react-native-renderer', | 244 | 253 | }); | 245 | | - | 246 | | -export default ReactNativeRenderer; | |
|