Skip to content

Commit 9006981

Browse files
SaadnajmiNick Lefever
andauthored
feat(fabric): add support for tooltip (#2714)
## Summary: Cherry pick a change from #2117 to add tooltip support ## Test Plan: Existing test page works --------- Co-authored-by: Nick Lefever <[email protected]>
1 parent 2dddc18 commit 9006981

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed

packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,17 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
588588
needsInvalidateLayer = YES;
589589
}
590590

591+
#if TARGET_OS_OSX // [macOS]
592+
// `tooltip`
593+
if (oldViewProps.tooltip != newViewProps.tooltip) {
594+
if (newViewProps.tooltip.has_value()) {
595+
self.toolTip = RCTNSStringFromStringNilIfEmpty(newViewProps.tooltip.value());
596+
} else {
597+
self.toolTip = nil;
598+
}
599+
}
600+
#endif // macOS]
601+
591602
_needsInvalidateLayer = _needsInvalidateLayer || needsInvalidateLayer;
592603

593604
_props = std::static_pointer_cast<const ViewProps>(props);

packages/react-native/ReactCommon/react/renderer/components/view/platform/macos/react/renderer/components/view/HostPlatformViewProps.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,16 @@ HostPlatformViewProps::HostPlatformViewProps(
6565
rawProps,
6666
"keyUpEvents",
6767
sourceProps.keyUpEvents,
68-
{})) {}
68+
{})),
69+
tooltip(
70+
ReactNativeFeatureFlags::enableCppPropsIteratorSetter()
71+
? sourceProps.tooltip
72+
: convertRawProp(
73+
context,
74+
rawProps,
75+
"tooltip",
76+
sourceProps.tooltip,
77+
{})) {}
6978

7079
#define VIEW_EVENT_CASE_MACOS(eventType) \
7180
case CONSTEXPR_RAW_PROPS_KEY_HASH("on" #eventType): { \
@@ -102,6 +111,7 @@ void HostPlatformViewProps::setProp(
102111
RAW_SET_PROP_SWITCH_CASE_BASIC(enableFocusRing);
103112
RAW_SET_PROP_SWITCH_CASE_BASIC(keyDownEvents);
104113
RAW_SET_PROP_SWITCH_CASE_BASIC(keyUpEvents);
114+
RAW_SET_PROP_SWITCH_CASE_BASIC(tooltip);
105115
}
106116
}
107117

packages/react-native/ReactCommon/react/renderer/components/view/platform/macos/react/renderer/components/view/HostPlatformViewProps.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
#include <react/renderer/components/view/KeyEvent.h>
1818

19+
#include <optional>
20+
#include <string>
21+
1922
#include "HostPlatformViewEvents.h"
2023

2124
namespace facebook::react {
@@ -43,5 +46,7 @@ class HostPlatformViewProps : public BaseViewProps {
4346

4447
std::vector<HandledKey> keyDownEvents{};
4548
std::vector<HandledKey> keyUpEvents{};
49+
50+
std::optional<std::string> tooltip{};
4651
};
4752
} // namespace facebook::react

packages/rn-tester/js/utils/RNTesterList.ios.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,6 @@ const Components: Array<RNTesterModuleInfo> = [
127127
module: require('../examples/TextInput/TextInputExample.ios'),
128128
category: 'Basic',
129129
},
130-
{
131-
key: 'TooltipExample',
132-
module: require('../examples/Tooltip/TooltipExample'),
133-
},
134130
{
135131
key: 'TouchableExample',
136132
module: require('../examples/Touchable/TouchableExample'),
@@ -186,6 +182,11 @@ const APIs: Array<RNTesterModuleInfo> = ([
186182
key: 'AccessibilityShowMenu',
187183
module: require('../examples/AccessibilityShowMenu/AccessibilityShowMenu'),
188184
category: 'macOS',
185+
},
186+
{
187+
key: 'TooltipExample',
188+
module: require('../examples/Tooltip/TooltipExample'),
189+
category: 'macOS',
189190
}, // macOS]
190191
{
191192
key: 'AccessibilityExample',

0 commit comments

Comments
 (0)