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

WIP - Fabric ScrollContentView 0_73 #10

Draft
wants to merge 4 commits into
base: 0.73-stable
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,18 @@
* @flow
*/

import type {
HostComponent,
PartialViewConfig,
} from '../../Renderer/shims/ReactNativeTypes';
import type {ViewProps as Props} from '../View/ViewPropTypes';
import type {HostComponent} from '../../Renderer/shims/ReactNativeTypes';
import type {ViewProps} from '../View/ViewPropTypes';

import * as NativeComponentRegistry from '../../NativeComponent/NativeComponentRegistry';
import codegenNativeComponent from '../../Utilities/codegenNativeComponent';

export const __INTERNAL_VIEW_CONFIG: PartialViewConfig = {
uiViewClassName: 'RCTScrollContentView',
bubblingEventTypes: {},
directEventTypes: {},
validAttributes: {},
};
type NativeProps = $ReadOnly<{|
...ViewProps,
inverted?: ?boolean,
|}>;

const ScrollContentViewNativeComponent: HostComponent<Props> =
NativeComponentRegistry.get<Props>(
'RCTScrollContentView',
() => __INTERNAL_VIEW_CONFIG,
);

export default ScrollContentViewNativeComponent;
export default (codegenNativeComponent<NativeProps>('ScrollContentView', {
paperComponentName: 'RCTScrollContentView',
excludedPlatforms: ['android'],
interfaceOnly: true,
}): HostComponent<NativeProps>);
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ Class<RCTComponentViewProtocol> RCTParagraphCls(void) __attribute__((used));
Class<RCTComponentViewProtocol> RCTPullToRefreshViewCls(void) __attribute__((used));
Class<RCTComponentViewProtocol> RCTSafeAreaViewCls(void) __attribute__((used));
Class<RCTComponentViewProtocol> RCTScrollViewCls(void) __attribute__((used));
#if TARGET_OS_OSX // [macOS
Class<RCTComponentViewProtocol> RCTScrollContentViewCls(void) __attribute__((used));
#endif // macOS]
Class<RCTComponentViewProtocol> RCTSwitchCls(void) __attribute__((used));
Class<RCTComponentViewProtocol> RCTTextInputCls(void) __attribute__((used));
Class<RCTComponentViewProtocol> RCTUnimplementedNativeViewCls(void) __attribute__((used));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
{"PullToRefreshView", RCTPullToRefreshViewCls},
{"SafeAreaView", RCTSafeAreaViewCls},
{"ScrollView", RCTScrollViewCls},
#if TARGET_OS_OSX // [macOS
{"ScrollContentView", RCTScrollContentViewCls},
#endif // macOS]
{"Switch", RCTSwitchCls},
{"TextInput", RCTTextInputCls},
{"UnimplementedNativeView", RCTUnimplementedNativeViewCls},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#import <React/RCTUIKit.h> // [macOS]

#import <React/RCTViewComponentView.h>

NS_ASSUME_NONNULL_BEGIN

@interface RCTScrollContentComponentView : RCTViewComponentView

@property (nonatomic, assign, getter=isInverted) BOOL inverted;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#import "RCTScrollContentComponentView.h"

#import <react/renderer/components/scrollview/ScrollContentViewComponentDescriptor.h>
#import <react/renderer/components/rncore/EventEmitters.h>
#import <react/renderer/components/rncore/Props.h>

#import "RCTFabricComponentsPlugins.h"

using namespace facebook::react;

@implementation RCTScrollContentComponentView

- (instancetype)init
{
if (self = [super init]) {
_props = std::make_shared<ScrollContentViewProps const>();
}

return self;
}

- (void)updateProps:(Props::Shared const&)props oldProps:(Props::Shared const&)oldProps {
const auto& newViewProps = *std::static_pointer_cast<ScrollContentViewProps const>(props);

[self setInverted:newViewProps.inverted];

[super updateProps:props oldProps:oldProps];
}

- (BOOL)isFlipped
{
return !self.inverted;
}

#pragma mark - RCTComponentViewProtocol

+ (ComponentDescriptorProvider)componentDescriptorProvider
{
return concreteComponentDescriptorProvider<ScrollContentViewComponentDescriptor>();
}

Class<RCTComponentViewProtocol> RCTScrollContentViewCls(void)
{
return RCTScrollContentComponentView.class;
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -382,19 +382,27 @@ - (void)_preserveContentOffsetIfNeededWithBlock:(void (^)())block

- (void)mountChildComponentView:(RCTUIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index // [macOS]
{
#if !TARGET_OS_OSX // [macOS]
[_containerView insertSubview:childComponentView atIndex:index];
if (![childComponentView conformsToProtocol:@protocol(RCTCustomPullToRefreshViewProtocol)]) {
_contentView = childComponentView;
}
#else // [macOS
[_scrollView setDocumentView:childComponentView];
#endif // macOS]
}

- (void)unmountChildComponentView:(RCTUIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index // [macOS]
{
#if !TARGET_OS_OSX // [macOS]
[childComponentView removeFromSuperview];
if (![childComponentView conformsToProtocol:@protocol(RCTCustomPullToRefreshViewProtocol)] &&
_contentView == childComponentView) {
_contentView = nil;
}
#else // [macOS
[_scrollView setDocumentView:_containerView];
#endif // macOS]
}

/*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#pragma once

#include <react/renderer/components/scrollview/ScrollContentViewShadowNode.h>
#include <react/renderer/core/ConcreteComponentDescriptor.h>

namespace facebook {
namespace react {

using ScrollContentViewComponentDescriptor =
ConcreteComponentDescriptor<ScrollContentViewShadowNode>;

} // namespace react
} // namespace facebook
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#include "ScrollContentViewShadowNode.h"

#include <react/debug/react_native_assert.h>
#include <react/renderer/core/LayoutMetrics.h>

namespace facebook::react {

const char ScrollContentViewComponentName[] = "ScrollContentView";

#if TARGET_OS_OSX // [macOS
bool ScrollContentViewShadowNode::getIsVerticalAxisFlipped() const {
return getConcreteProps().inverted;
}
#endif // macOS]

} // namespace facebook::react
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#pragma once

#include <react/renderer/components/rncore/Props.h>
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
#include <react/renderer/core/LayoutContext.h>

namespace facebook {
namespace react {

extern const char ScrollContentViewComponentName[];

/*
* `ShadowNode` for <ScrollContentView> component.
*/
class ScrollContentViewShadowNode final : public ConcreteViewShadowNode<
ScrollContentViewComponentName,
ScrollContentViewProps> {
public:
using ConcreteViewShadowNode::ConcreteViewShadowNode;

#pragma mark - LayoutableShadowNode

#if TARGET_OS_OSX // [macOS
bool getIsVerticalAxisFlipped() const override;
#endif // macOS]
};

} // namespace react
} // namespace facebook
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,10 @@ Point ScrollViewShadowNode::getContentOriginOffset() const {
return {-contentOffset.x, -contentOffset.y + stateData.scrollAwayPaddingTop};
}

#if TARGET_OS_OSX // [macOS
bool ScrollViewShadowNode::getIsVerticalAxisFlipped() const {
return getConcreteProps().inverted;
}
#endif // macOS]

} // namespace facebook::react
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ class ScrollViewShadowNode final : public ConcreteViewShadowNode<
void layout(LayoutContext layoutContext) override;
Point getContentOriginOffset() const override;

#if TARGET_OS_OSX // [macOS
bool getIsVerticalAxisFlipped() const override;
#endif // macOS]

private:
void updateStateIfNeeded();
void updateScrollContentOffsetIfNeeded();
Expand Down