Skip to content

Commit db882e9

Browse files
authoredAug 9, 2023
Add new macOS View prop allowsVibrancy (microsoft#1889)
* Add new macOS View prop `allowsVibrancy` * fix lint * small fixes * fix lint * no super
1 parent 663773c commit db882e9

File tree

7 files changed

+31
-0
lines changed

7 files changed

+31
-0
lines changed
 

‎Libraries/Components/Pressable/Pressable.js

+10
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,16 @@ type Props = $ReadOnly<{|
232232
*/
233233
enableFocusRing?: ?boolean,
234234

235+
/**
236+
* Specifies whether the view ensures it is vibrant on top of other content.
237+
* For more information, see the following apple documentation:
238+
* https://developer.apple.com/documentation/appkit/nsview/1483793-allowsvibrancy
239+
* https://developer.apple.com/documentation/appkit/nsvisualeffectview#1674177
240+
*
241+
* @platform macos
242+
*/
243+
allowsVibrancy?: ?boolean,
244+
235245
/**
236246
* Specifies the Tooltip for the Pressable.
237247
* @platform macos

‎Libraries/Components/View/ViewPropTypes.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ export type DraggedTypesType = DraggedType | DraggedType[];
173173

174174
export interface ViewPropsMacOS {
175175
acceptsFirstMouse?: boolean | undefined;
176+
allowsVibrancy?: boolean | undefined;
176177
mouseDownCanMoveWindow?: boolean | undefined;
177178
enableFocusRing?: boolean | undefined;
178179
onMouseEnter?: ((event: MouseEvent) => void) | undefined;

‎Libraries/Components/View/ViewPropTypes.js

+10
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,16 @@ type MacOSViewProps = $ReadOnly<{|
553553
*/
554554
mouseDownCanMoveWindow?: ?boolean,
555555

556+
/**
557+
* Specifies whether the view ensures it is vibrant on top of other content.
558+
* For more information, see the following apple documentation:
559+
* https://developer.apple.com/documentation/appkit/nsview/1483793-allowsvibrancy
560+
* https://developer.apple.com/documentation/appkit/nsvisualeffectview#1674177
561+
*
562+
* @platform macos
563+
*/
564+
allowsVibrancy?: ?boolean,
565+
556566
/**
557567
* Specifies whether system focus ring should be drawn when the view has keyboard focus.
558568
*

‎Libraries/NativeComponent/BaseViewConfig.macos.js

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const directEventTypes = {
4848
const validAttributesForNonEventProps = {
4949
acceptsFirstMouse: true,
5050
accessibilityTraits: true,
51+
allowsVibrancy: true,
5152
cursor: true,
5253
draggedTypes: true,
5354
enableFocusRing: true,

‎React/Views/RCTView.h

+4
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ extern const UIAccessibilityTraits SwitchAccessibilityTrait;
156156

157157
@property (nonatomic, assign) CATransform3D transform3D;
158158

159+
// `allowsVibrancy` is readonly on NSView, so let's create a new property to make it assignable
160+
// that we can set through JS and the getter for `allowsVibrancy` can read in RCTView.
161+
@property (nonatomic, assign) BOOL allowsVibrancyInternal;
162+
159163
@property (nonatomic, copy) RCTDirectEventBlock onMouseEnter;
160164
@property (nonatomic, copy) RCTDirectEventBlock onMouseLeave;
161165
@property (nonatomic, copy) RCTDirectEventBlock onDragEnter;

‎React/Views/RCTView.m

+3
Original file line numberDiff line numberDiff line change
@@ -1519,6 +1519,9 @@ - (void)setMouseDownCanMoveWindow:(BOOL)mouseDownCanMoveWindow{
15191519
_mouseDownCanMoveWindow = mouseDownCanMoveWindow;
15201520
}
15211521

1522+
- (BOOL)allowsVibrancy {
1523+
return _allowsVibrancyInternal;
1524+
}
15221525

15231526
- (NSDictionary*)locationInfoFromEvent:(NSEvent*)event
15241527
{

‎React/Views/RCTViewManager.m

+2
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,8 @@ - (RCTShadowView *)shadowView
430430

431431
RCT_EXPORT_VIEW_PROPERTY(mouseDownCanMoveWindow, BOOL)
432432

433+
RCT_REMAP_VIEW_PROPERTY(allowsVibrancy, allowsVibrancyInternal, BOOL)
434+
433435
RCT_CUSTOM_VIEW_PROPERTY(focusable, BOOL, RCTView)
434436
{
435437
if ([view respondsToSelector:@selector(setFocusable:)]) {

0 commit comments

Comments
 (0)
Please sign in to comment.