Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from facebook:master #360

Merged
merged 6 commits into from
Nov 4, 2020
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<span> · </span>
<a href="https://reactnative.dev/docs/contributing">Contribute</a>
<span> · </span>
<a href="https://reactnative.dev/en/help">Community</a>
<a href="https://reactnative.dev/help">Community</a>
<span> · </span>
<a href="https://github.com/facebook/react-native/blob/master/.github/SUPPORT.md">Support</a>
</h3>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
using namespace facebook::react;

@implementation RCTSafeAreaViewComponentView {
SafeAreaViewShadowNode::ConcreteStateTeller _stateTeller;
EdgeInsets _lastPaddingStateWasUpdatedWith;
SafeAreaViewShadowNode::ConcreteState::Shared _state;
}

- (instancetype)initWithFrame:(CGRect)frame
Expand Down Expand Up @@ -50,6 +49,10 @@ - (void)safeAreaInsetsDidChange

- (void)_updateStateIfNecessary
{
if (!_state) {
return;
}

UIEdgeInsets insets = [self _safeAreaInsets];
insets.left = RCTRoundPixelValue(insets.left);
insets.top = RCTRoundPixelValue(insets.top);
Expand All @@ -58,35 +61,47 @@ - (void)_updateStateIfNecessary

auto newPadding = RCTEdgeInsetsFromUIEdgeInsets(insets);
auto threshold = 1.0 / RCTScreenScale() + 0.01; // Size of a pixel plus some small threshold.
auto deltaPadding = newPadding - _lastPaddingStateWasUpdatedWith;

if (std::abs(deltaPadding.left) < threshold && std::abs(deltaPadding.top) < threshold &&
std::abs(deltaPadding.right) < threshold && std::abs(deltaPadding.bottom) < threshold) {
return;
}

_lastPaddingStateWasUpdatedWith = newPadding;
_stateTeller.updateState(SafeAreaViewState{newPadding});
_state->updateStateWithAutorepeat(
[=](SafeAreaViewShadowNode::ConcreteState::Data const &oldData)
-> SafeAreaViewShadowNode::ConcreteState::SharedData {
auto oldPadding = oldData.padding;
auto deltaPadding = newPadding - oldPadding;

if (std::abs(deltaPadding.left) < threshold && std::abs(deltaPadding.top) < threshold &&
std::abs(deltaPadding.right) < threshold && std::abs(deltaPadding.bottom) < threshold) {
return nullptr;
}

auto newData = oldData;
newData.padding = newPadding;
return std::make_shared<SafeAreaViewShadowNode::ConcreteState::Data>(newData);
});
}

#pragma mark - RCTComponentViewProtocol

- (void)updateState:(State::Shared const &)state oldState:(State::Shared const &)oldState
+ (ComponentDescriptorProvider)componentDescriptorProvider
{
_stateTeller.setConcreteState(state);
[self _updateStateIfNecessary];
return concreteComponentDescriptorProvider<SafeAreaViewComponentDescriptor>();
}

- (void)prepareForRecycle
- (void)updateState:(facebook::react::State::Shared const &)state
oldState:(facebook::react::State::Shared const &)oldState
{
[super prepareForRecycle];
_stateTeller.invalidate();
_lastPaddingStateWasUpdatedWith = {};
_state = std::static_pointer_cast<SafeAreaViewShadowNode::ConcreteState const>(state);
}

+ (ComponentDescriptorProvider)componentDescriptorProvider
- (void)finalizeUpdates:(RNComponentViewUpdateMask)updateMask
{
return concreteComponentDescriptorProvider<SafeAreaViewComponentDescriptor>();
[super finalizeUpdates:updateMask];
[self _updateStateIfNecessary];
}

- (void)prepareForRecycle
{
[super prepareForRecycle];
_state.reset();
}

@end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ class JSI_EXPORT ObjCTurboModule : public TurboModule {
*/
@property (nonatomic, weak) id<RCTTurboModuleRegistry> turboModuleRegistry;

@optional
// This should be required, after migration is done.
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
(const facebook::react::ObjCTurboModule::InitParams &)params;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ class SafeAreaViewShadowNode final : public ConcreteViewShadowNode<
ViewEventEmitter,
SafeAreaViewState> {
using ConcreteViewShadowNode::ConcreteViewShadowNode;

public:
static ShadowNodeTraits BaseTraits() {
auto traits = ConcreteViewShadowNode::BaseTraits();
traits.set(
ShadowNodeTraits::Trait::YogaLayoutableKindMutatesStylesAfterCloning);
return traits;
}
};

} // namespace react
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ namespace react {
*/
class SafeAreaViewState final {
public:
using Shared = std::shared_ptr<SafeAreaViewState const>;

EdgeInsets const padding{};
EdgeInsets padding{};
};

} // namespace react
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ YogaLayoutableShadowNode::YogaLayoutableShadowNode(
static_cast<YogaLayoutableShadowNode const &>(sourceShadowNode)
.yogaNode_.isDirty() == yogaNode_.isDirty());

if (getTraits().check(ShadowNodeTraits::Trait::
YogaLayoutableKindMutatesStylesAfterCloning)) {
yogaNode_.setDirty(true);
}

if (fragment.props) {
updateYogaProps();
}
Expand Down
6 changes: 6 additions & 0 deletions ReactCommon/react/renderer/core/ShadowNodeTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ class ShadowNodeTraits {
// Nodes with this trait (and all their descendants) will not produce views.
Hidden = 1 << 6,

// Indicates that the `YogaLayoutableShadowNode` must set `isDirty` flag for
// Yoga node when a `ShadowNode` is being cloned. `ShadowNode`s that modify
// Yoga styles in the constructor (or later) *after* the `ShadowNode`
// is cloned must set this trait.
YogaLayoutableKindMutatesStylesAfterCloning = 1 << 7,

// Inherits `YogaLayoutableShadowNode` and enforces that the `YGNode` is a
// leaf.
LeafYogaNode = 1 << 10,
Expand Down
1 change: 0 additions & 1 deletion packages/assets/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ rn_library(
labels = ["supermodule:xplat/default/public.react_native.core"],
skip_processors = True,
visibility = ["PUBLIC"],
worker = "//xplat/js:metro-transform-worker",
)

yarn_workspace(
Expand Down
1 change: 0 additions & 1 deletion packages/normalize-color/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ rn_library(
labels = ["supermodule:xplat/default/public.react_native.core"],
skip_processors = True,
visibility = ["PUBLIC"],
worker = "//xplat/js:metro-transform-worker",
)

yarn_workspace(
Expand Down