Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
{
// Prop updates are ignored by _refreshControl until after the initial layout, so just store them in _props until then
if (_isBeforeInitialLayout) {
_props = std::static_pointer_cast<const BaseViewProps>(props);
_props = std::static_pointer_cast<const PullToRefreshViewProps>(props); // [macOS]
return;
}

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

// [macOS]

#pragma once

#include <react/renderer/components/view/BaseTouch.h>

namespace facebook::react {
using HostPlatformTouch = BaseTouch;
} // namespace facebook::react
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) Microsoft Corporation.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

// [macOS]

#include <react/renderer/components/view/HostPlatformViewEventEmitter.h>

namespace facebook::react {

#pragma mark - Focus Events

void HostPlatformViewEventEmitter::onFocus() const {
dispatchEvent("focus");
}

void HostPlatformViewEventEmitter::onBlur() const {
dispatchEvent("blur");
}

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

// [macOS]

#pragma once

#include <react/renderer/components/view/BaseViewEventEmitter.h>

namespace facebook::react {

class HostPlatformViewEventEmitter : public BaseViewEventEmitter {
public:
using BaseViewEventEmitter::BaseViewEventEmitter;

#pragma mark - Focus Events

void onFocus() const;
void onBlur() const;
};

} // namespace facebook::react
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* 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 "HostPlatformViewProps.h"

#include <algorithm>

#include <react/featureflags/ReactNativeFeatureFlags.h>
#include <react/renderer/components/view/conversions.h>
#include <react/renderer/components/view/propsConversions.h>
#include <react/renderer/core/graphicsConversions.h>
#include <react/renderer/core/propsConversions.h>

namespace facebook::react {

HostPlatformViewProps::HostPlatformViewProps(
const PropsParserContext& context,
const HostPlatformViewProps& sourceProps,
const RawProps& rawProps)
: BaseViewProps(context, sourceProps, rawProps),
macOSViewEvents(
ReactNativeFeatureFlags::enableCppPropsIteratorSetter()
? sourceProps.macOSViewEvents
: convertRawProp(
context,
rawProps,
sourceProps.macOSViewEvents,
{})),
focusable(
ReactNativeFeatureFlags::enableCppPropsIteratorSetter()
? sourceProps.focusable
: convertRawProp(
context,
rawProps,
"focusable",
sourceProps.focusable,
{})),
enableFocusRing(
ReactNativeFeatureFlags::enableCppPropsIteratorSetter()
? sourceProps.enableFocusRing
: convertRawProp(
context,
rawProps,
"enableFocusRing",
sourceProps.enableFocusRing,
{})) {}

#define MACOS_VIEW_EVENT_CASE(eventType) \
case CONSTEXPR_RAW_PROPS_KEY_HASH("on" #eventType): { \
const auto offset = MacOSViewEvents::Offset::eventType; \
MacOSViewEvents defaultViewEvents{}; \
bool res = defaultViewEvents[offset]; \
if (value.hasValue()) { \
fromRawValue(context, value, res); \
} \
macOSViewEvents[offset] = res; \
return; \
}

void HostPlatformViewProps::setProp(
const PropsParserContext& context,
RawPropsPropNameHash hash,
const char* propName,
const RawValue& value) {
// All Props structs setProp methods must always, unconditionally,
// call all super::setProp methods, since multiple structs may
// reuse the same values.
BaseViewProps::setProp(context, hash, propName, value);

static auto defaults = HostPlatformViewProps{};

switch (hash) {
RAW_SET_PROP_SWITCH_CASE_BASIC(focusable);
RAW_SET_PROP_SWITCH_CASE_BASIC(enableFocusRing);
MACOS_VIEW_EVENT_CASE(Focus);
MACOS_VIEW_EVENT_CASE(Blur);

}
}


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

// [macOS]

#pragma once

#include <react/renderer/components/view/BaseViewProps.h>
#include <react/renderer/components/view/primitives.h>
#include <react/renderer/core/Props.h>
#include <react/renderer/core/PropsParserContext.h>

#include "MacOSViewEvents.h"

namespace facebook::react {

class HostPlatformViewProps : public BaseViewProps {
public:
HostPlatformViewProps() = default;
HostPlatformViewProps(
const PropsParserContext& context,
const HostPlatformViewProps& sourceProps,
const RawProps& rawProps);

void setProp(
const PropsParserContext& context,
RawPropsPropNameHash hash,
const char* propName,
const RawValue& value);

MacOSViewEvents macOSViewEvents{};

#pragma mark - Props

bool focusable{false};
bool enableFocusRing{true};

};
} // namespace facebook::react
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.
*/

#pragma once

#include <react/renderer/components/view/ViewProps.h>
#include <react/renderer/core/ShadowNodeTraits.h>

namespace facebook::react::HostPlatformViewTraitsInitializer {

inline bool formsStackingContext(const ViewProps& props) {
return false;
}

inline bool formsView(const ViewProps& props) {
return props.focusable;
}

} // namespace facebook::react::HostPlatformViewTraitsInitializer
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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/core/PropsParserContext.h>
#include <react/renderer/core/propsConversions.h>

#include <bitset>

namespace facebook::react {

struct MacOSViewEvents {
std::bitset<64> bits{};

enum class Offset : std::size_t {
// Focus Events
Focus = 0,
Blur = 1,
};

constexpr bool operator[](const Offset offset) const {
return bits[static_cast<std::size_t >(offset)];
}

std::bitset<64>::reference operator[](const Offset offset) {
return bits[static_cast<std::size_t >(offset)];
}
};

inline static bool operator==(MacOSViewEvents const &lhs, MacOSViewEvents const &rhs) {
return lhs.bits == rhs.bits;
}

inline static bool operator!=(MacOSViewEvents const &lhs, MacOSViewEvents const &rhs) {
return lhs.bits != rhs.bits;
}

static inline MacOSViewEvents convertRawProp(
const PropsParserContext &context,
const RawProps &rawProps,
const MacOSViewEvents &sourceValue,
const MacOSViewEvents &defaultValue) {
MacOSViewEvents result{};
using Offset = MacOSViewEvents::Offset;

// Focus Events
result[Offset::Focus] =
convertRawProp(context, rawProps, "onFocus", sourceValue[Offset::Focus], defaultValue[Offset::Focus]);
result[Offset::Blur] =
convertRawProp(context, rawProps, "onBlur", sourceValue[Offset::Blur], defaultValue[Offset::Blur]);

return result;
}

} // namespace facebook::react
Loading