Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add focus props
  • Loading branch information
Saadnajmi committed Sep 16, 2025
commit 19aa285c323f7ca604b5cf1df4e16f8d90f808e9
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,36 @@
*/

// [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>

namespace facebook::react {
using HostPlatformViewProps = BaseViewProps;

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
Expand Up @@ -17,7 +17,7 @@ inline bool formsStackingContext(const ViewProps& props) {
}

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

} // 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<8> bits{}; // TODO: Windows sets this to 32.. should we be higher?

enum class Offset : uint8_t { // TODO: Windows sets this and others to std::size_t instead of uint8_t.. should we?
// Focus Events
Focus = 0,
Blur = 1,
};

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

std::bitset<8>::reference operator[](const Offset offset) {
return bits[static_cast<uint8_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