Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.
Merged
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
9 changes: 9 additions & 0 deletions backend/getData.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ function getData(internalInstance: Object): DataType {
}
}

if (typeof internalInstance.setNativeProps === 'function') {
// For editing styles in RN
updater = {
setNativeProps(nativeProps) {
internalInstance.setNativeProps(nativeProps);
},
};
}

return {
nodeType,
type,
Expand Down
23 changes: 21 additions & 2 deletions backend/getDataFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ function getDataFiber(fiber: Object, getOpaqueNode: (fiber: Object) => Object):
break;
case HostComponent:
nodeType = 'Native';
name = fiber.type;
name = typeof fiber.type === 'string' ?
fiber.type :
// Necessary for React Native Fiber if host types are not strings.
// https://github.com/facebook/react/pull/9013
getDisplayName(fiber.type);
publicInstance = fiber.stateNode;
props = fiber.memoizedProps;
if (
Expand All @@ -91,6 +95,14 @@ function getDataFiber(fiber: Object, getOpaqueNode: (fiber: Object) => Object):
} else {
children = [];
}
if (typeof fiber.stateNode.setNativeProps === 'function') {
// For editing styles in RN
updater = {
setNativeProps(nativeProps) {
fiber.stateNode.setNativeProps(nativeProps);
},
};
}
break;
case HostText:
nodeType = 'Text';
Expand Down Expand Up @@ -134,7 +146,14 @@ function getDataFiber(fiber: Object, getOpaqueNode: (fiber: Object) => Object):
}

function setInProps(fiber, path: Array<string | number>, value: any) {
fiber.pendingProps = copyWithSet(fiber.memoizedProps, path, value);
const inst = fiber.stateNode;
fiber.pendingProps = copyWithSet(inst.props, path, value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sebmarkbage @acdlite is this logic still applicable given the recent changes to how fiber will work with async?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In facebook/react#9695, we never read pendingProps from the current tree, so I think this is fine.

if (fiber.alternate) {
// We don't know which fiber is the current one because DevTools may bail out of getDataFiber() call,
// and so the data object may refer to another version of the fiber. Therefore we update pendingProps
// on both. I hope that this is safe.
fiber.alternate.pendingProps = fiber.pendingProps;
}
fiber.stateNode.forceUpdate();
}

Expand Down
19 changes: 12 additions & 7 deletions backend/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@
*/
'use strict';

type CompositeUpdater = {
setInProps: ?(path: Array<string>, value: any) => void,
setInState: ?(path: Array<string>, value: any) => void,
setInContext: ?(path: Array<string>, value: any) => void,
forceUpdate: ?() => void,
};

type NativeUpdater = {
setNativeProps: ?(nativeProps: {[key: string]: any}) => void,
};

export type DataType = {
nodeType: 'Native' | 'Wrapper' | 'NativeWrapper' | 'Composite' | 'Text' | 'Portal' | 'Empty',
type: ?(string | AnyFn),
Expand All @@ -22,13 +33,7 @@ export type DataType = {
context: ?Object,
children: ?(string | Array<OpaqueNodeHandle>),
text: ?string,
updater: ?{
setInProps: ?(path: Array<string>, value: any) => void,
setInState: ?(path: Array<string>, value: any) => void,
setInContext: ?(path: Array<string>, value: any) => void,
// setState: ?(newState: any) => void,
forceUpdate: ?() => void,
},
updater: ?(CompositeUpdater | NativeUpdater),
publicInstance: ?Object,
};

Expand Down