Skip to content

Commit

Permalink
Add new macOS View prop allowsVibrancy (#1889) (#1900)
Browse files Browse the repository at this point in the history
* Add new macOS View prop `allowsVibrancy`

* fix lint

* small fixes

* fix lint

* no super
  • Loading branch information
Saadnajmi authored Aug 9, 2023
1 parent 2ec117d commit 8cf231a
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 0 deletions.
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 @@ -152,6 +152,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 @@ -1509,6 +1509,9 @@ - (void)setMouseDownCanMoveWindow:(BOOL)mouseDownCanMoveWindow{
_mouseDownCanMoveWindow = mouseDownCanMoveWindow;
}

- (BOOL)allowsVibrancy {
return _allowsVibrancyInternal;
}

- (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 @@ -420,6 +420,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

0 comments on commit 8cf231a

Please sign in to comment.