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

Add new macOS View prop allowsVibrancy #1889

Merged
merged 6 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
10 changes: 10 additions & 0 deletions Libraries/Components/Pressable/Pressable.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,16 @@ type Props = $ReadOnly<{|
*/
enableFocusRing?: ?boolean,

/**
* Specifies whether the view ensures it is vibrant on top of other content.
* For more information, see the following apple documentation:
* https://developer.apple.com/documentation/appkit/nsview/1483793-allowsvibrancy
* https://developer.apple.com/documentation/appkit/nsvisualeffectview#1674177
*
* @platform macos
*/
allowsVibrancy?: ?boolean,

/**
* Specifies the Tooltip for the Pressable.
* @platform macos
Expand Down
1 change: 1 addition & 0 deletions Libraries/Components/View/ViewPropTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ export type DraggedTypesType = DraggedType | DraggedType[];

export interface ViewPropsMacOS {
acceptsFirstMouse?: boolean | undefined;
allowsVibrancy?: boolean | undefined;
mouseDownCanMoveWindow?: boolean | undefined;
enableFocusRing?: boolean | undefined;
onMouseEnter?: ((event: MouseEvent) => void) | undefined;
Expand Down
10 changes: 10 additions & 0 deletions Libraries/Components/View/ViewPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,16 @@ type MacOSViewProps = $ReadOnly<{|
*/
mouseDownCanMoveWindow?: ?boolean,

/**
* Specifies whether the view ensures it is vibrant on top of other content.
* For more information, see the following apple documentation:
* https://developer.apple.com/documentation/appkit/nsview/1483793-allowsvibrancy
* https://developer.apple.com/documentation/appkit/nsvisualeffectview#1674177
*
* @platform macos
*/
allowsVibrancy?: ?boolean,

/**
* Specifies whether system focus ring should be drawn when the view has keyboard focus.
*
Expand Down
1 change: 1 addition & 0 deletions Libraries/NativeComponent/BaseViewConfig.macos.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const directEventTypes = {
const validAttributesForNonEventProps = {
acceptsFirstMouse: true,
accessibilityTraits: true,
allowsVibrancy: true,
cursor: true,
draggedTypes: true,
enableFocusRing: true,
Expand Down
4 changes: 4 additions & 0 deletions React/Views/RCTView.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ extern const UIAccessibilityTraits SwitchAccessibilityTrait;

@property (nonatomic, assign) CATransform3D transform3D;

// `allowsVibrancy` is readonly on NSView, so let's create a new property to make it assignable
// that we can set through JS and the getter for `allowsVibrancy` can read in RCTView.
@property (nonatomic, assign) BOOL allowsVibrancyInternal;

@property (nonatomic, copy) RCTDirectEventBlock onMouseEnter;
@property (nonatomic, copy) RCTDirectEventBlock onMouseLeave;
@property (nonatomic, copy) RCTDirectEventBlock onDragEnter;
Expand Down
3 changes: 3 additions & 0 deletions React/Views/RCTView.m
Original file line number Diff line number Diff line change
Expand Up @@ -1519,6 +1519,9 @@ - (void)setMouseDownCanMoveWindow:(BOOL)mouseDownCanMoveWindow{
_mouseDownCanMoveWindow = mouseDownCanMoveWindow;
}

- (BOOL)allowsVibrancy {
return _allowsVibrancyInternal || [super allowsVibrancy];
}

- (NSDictionary*)locationInfoFromEvent:(NSEvent*)event
{
Expand Down
2 changes: 2 additions & 0 deletions React/Views/RCTViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,8 @@ - (RCTShadowView *)shadowView

RCT_EXPORT_VIEW_PROPERTY(mouseDownCanMoveWindow, BOOL)

RCT_REMAP_VIEW_PROPERTY(allowsVibrancy, allowsVibrancyInternal, BOOL)

RCT_CUSTOM_VIEW_PROPERTY(focusable, BOOL, RCTView)
{
if ([view respondsToSelector:@selector(setFocusable:)]) {
Expand Down