Skip to content

Commit

Permalink
Allow out of tree platforms to customize cursor values (facebook#44841)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#44841

Out of tree platforms like react-native-macos and react-native-windows may wish to support different cursor types than are currently supported in mobile React Native (currently only "auto" and "pointer").

Since the Cursor is applied on the BaseViewProps across all platforms, we need an extension point where a platform can inject it's own header for defining a cursor. This header will also have to include it's own implementation of `fromRawValue` to parse the cursor value from RawProps into the host platform implementation of Cursor.

## Changelog

[Internal]

Differential Revision: D58301970
  • Loading branch information
rozele authored and facebook-github-bot committed Jun 8, 2024
1 parent 61de7da commit d1edbf1
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#pragma once

#include <react/renderer/components/view/AccessibilityProps.h>
#include <react/renderer/components/view/HostPlatformCursor.h>
#include <react/renderer/components/view/YogaStylableProps.h>
#include <react/renderer/components/view/primitives.h>
#include <react/renderer/core/LayoutMetrics.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -758,19 +758,19 @@ inline void fromRawValue(
inline void fromRawValue(
const PropsParserContext& context,
const RawValue& value,
Cursor& result) {
result = Cursor::Auto;
BaseCursor& result) {
result = BaseCursor::Auto;
react_native_expect(value.hasType<std::string>());
if (!value.hasType<std::string>()) {
return;
}
auto stringValue = (std::string)value;
if (stringValue == "auto") {
result = Cursor::Auto;
result = BaseCursor::Auto;
return;
}
if (stringValue == "pointer") {
result = Cursor::Pointer;
result = BaseCursor::Pointer;
return;
}
LOG(ERROR) << "Could not parse Cursor:" << stringValue;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* 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/primitives.h>

namespace facebook::react {
using Cursor = BaseCursor;
} // namespace facebook::react
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* 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/primitives.h>

namespace facebook::react {
using Cursor = BaseCursor;
} // namespace facebook::react
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ enum class BorderCurve : uint8_t { Circular, Continuous };

enum class BorderStyle : uint8_t { Solid, Dotted, Dashed };

enum class Cursor : uint8_t { Auto, Pointer };
enum class BaseCursor : uint8_t { Auto, Pointer };

enum class LayoutConformance : uint8_t { Undefined, Classic, Strict };

Expand Down

0 comments on commit d1edbf1

Please sign in to comment.