diff --git a/ios/JsonCanvasGlass.m b/ios/JsonCanvasGlass.m deleted file mode 100644 index d9222ba..0000000 --- a/ios/JsonCanvasGlass.m +++ /dev/null @@ -1,150 +0,0 @@ -// Liquid Glass for React Native on the Mac, which has none of its own: -// - JsonCanvasGlass: glass behind a view (the minimap's default background). -// NSGlassEffectView from macOS 26, a visual effect view before it. -// - JsonCanvasGlassButton: the system's own glass button (NSButton with the -// glass bezel from macOS 26), an SF Symbol in it, for a canvas's controls. - -#if TARGET_OS_OSX - -#import -#import - -@interface JsonCanvasGlassView : NSView -@property (nonatomic, assign) CGFloat cornerRadius; -@end - -@implementation JsonCanvasGlassView { - NSView *_glass; -} - -- (instancetype)initWithFrame:(NSRect)frame -{ - if ((self = [super initWithFrame:frame])) { - self.wantsLayer = YES; - Class glassClass = NSClassFromString(@"NSGlassEffectView"); - if (glassClass != nil) { - _glass = [[glassClass alloc] initWithFrame:self.bounds]; - } else { - NSVisualEffectView *effect = [[NSVisualEffectView alloc] initWithFrame:self.bounds]; - effect.material = NSVisualEffectMaterialHUDWindow; - effect.blendingMode = NSVisualEffectBlendingModeWithinWindow; - effect.state = NSVisualEffectStateActive; - effect.wantsLayer = YES; - effect.layer.masksToBounds = YES; - _glass = effect; - } - _glass.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable; - // Behind whatever React Native puts in this view. - [self addSubview:_glass positioned:NSWindowBelow relativeTo:nil]; - self.cornerRadius = 10; - } - return self; -} - -- (void)setCornerRadius:(CGFloat)cornerRadius -{ - _cornerRadius = cornerRadius; - if ([_glass respondsToSelector:@selector(setCornerRadius:)]) { - [(id)_glass setCornerRadius:cornerRadius]; - } else { - _glass.layer.cornerRadius = cornerRadius; - } -} - -- (void)layout -{ - [super layout]; - _glass.frame = self.bounds; - // React Native adds its children after the glass: keep the glass at the back. - if (self.subviews.firstObject != _glass) { - [_glass removeFromSuperview]; - [self addSubview:_glass positioned:NSWindowBelow relativeTo:nil]; - } -} - -@end - -@interface JsonCanvasGlassManager : RCTViewManager -@end - -@implementation JsonCanvasGlassManager - -RCT_EXPORT_MODULE(JsonCanvasGlass) - -- (RCTPlatformView *)view -{ - return [[JsonCanvasGlassView alloc] initWithFrame:NSZeroRect]; -} - -RCT_EXPORT_VIEW_PROPERTY(cornerRadius, CGFloat) - -@end - -@interface JsonCanvasGlassButton : NSButton -@property (nonatomic, copy) NSString *symbol; -@property (nonatomic, copy) NSString *help; -@property (nonatomic, copy) RCTBubblingEventBlock onGlassPress; -@end - -@implementation JsonCanvasGlassButton - -- (instancetype)initWithFrame:(NSRect)frame -{ - if ((self = [super initWithFrame:frame])) { - self.title = @""; - self.imagePosition = NSImageOnly; - self.target = self; - self.action = @selector(pressed); - if (@available(macOS 26.0, *)) { - self.bezelStyle = NSBezelStyleGlass; - self.borderShape = NSControlBorderShapeCircle; - } else { - self.bezelStyle = NSBezelStyleCircular; - } - } - return self; -} - -- (void)setSymbol:(NSString *)symbol -{ - _symbol = [symbol copy]; - NSImage *image = [NSImage imageWithSystemSymbolName:symbol accessibilityDescription:_help]; - NSImageSymbolConfiguration *config = [NSImageSymbolConfiguration configurationWithPointSize:13 weight:NSFontWeightMedium]; - self.image = [image imageWithSymbolConfiguration:config]; -} - -- (void)setHelp:(NSString *)help -{ - _help = [help copy]; - self.toolTip = help; - [self setAccessibilityLabel:help]; -} - -- (BOOL)acceptsFirstMouse:(NSEvent *)event { return YES; } - -- (void)pressed -{ - if (_onGlassPress) _onGlassPress(@{}); -} - -@end - -@interface JsonCanvasGlassButtonManager : RCTViewManager -@end - -@implementation JsonCanvasGlassButtonManager - -RCT_EXPORT_MODULE(JsonCanvasGlassButton) - -- (RCTPlatformView *)view -{ - return [[JsonCanvasGlassButton alloc] initWithFrame:NSZeroRect]; -} - -RCT_EXPORT_VIEW_PROPERTY(symbol, NSString) -RCT_EXPORT_VIEW_PROPERTY(help, NSString) -RCT_EXPORT_VIEW_PROPERTY(onGlassPress, RCTBubblingEventBlock) - -@end - -#endif diff --git a/src/index.ts b/src/index.ts index 2bd85fa..e4cab81 100644 --- a/src/index.ts +++ b/src/index.ts @@ -31,7 +31,6 @@ export {createCanvasState, type CanvasState} from './core/canvas-state'; export {CanvasView, type CanvasCamera, type FindResult} from './renderer/CanvasView'; export {nodesMatching} from './renderer/findNodes'; export {CanvasMinimap, type Insets, type MinimapPosition} from './renderer/CanvasMinimap'; -export {CanvasGlass, CanvasGlassButton, type CanvasGlassProps, type CanvasGlassButtonProps} from './renderer/CanvasGlass'; export {getNodeColors, resolveScheme, type ColorScheme} from './renderer/theme'; export {useCanvasContext, CanvasProvider} from './renderer/CanvasContext'; export {activateScrollWheel, deactivateScrollWheel} from './renderer/NativeScrollWheelView'; diff --git a/src/renderer/CanvasGlass.tsx b/src/renderer/CanvasGlass.tsx deleted file mode 100644 index ebf8af9..0000000 --- a/src/renderer/CanvasGlass.tsx +++ /dev/null @@ -1,49 +0,0 @@ -import React from 'react'; -import {Platform, requireNativeComponent, StyleSheet, View, type ViewProps} from 'react-native'; - -export interface CanvasGlassProps extends ViewProps { - /** The glass's corner radius, in points. */ - cornerRadius?: number; -} - -const NativeGlass = - Platform.OS === 'macos' ? requireNativeComponent('JsonCanvasGlass') : null; - -/** - * Liquid Glass behind its children, on the Mac (NSGlassEffectView; a visual - * effect view before macOS 26): the minimap's default background there, and - * a surface for a host's own canvas controls. Elsewhere a plain view: iOS - * hosts pass their own glass (expo-glass-effect) through `minimapBackground`. - */ -export function CanvasGlass({cornerRadius, style, ...props}: CanvasGlassProps) { - if (NativeGlass) return ; - return ; -} - -const styles = StyleSheet.create({ - clip: {overflow: 'hidden'}, -}); - -export interface CanvasGlassButtonProps extends ViewProps { - /** An SF Symbol's name. */ - symbol: string; - /** Its tooltip and accessibility label. */ - help: string; - onPress: () => void; -} - -const NativeGlassButton = - Platform.OS === 'macos' - ? requireNativeComponent & {onGlassPress: () => void}>('JsonCanvasGlassButton') - : null; - -/** - * The Mac's own Liquid Glass button (an NSButton with the system's glass - * bezel, macOS 26) showing an SF Symbol: for a host's canvas controls, such - * as Recenter and Fit. Null where there's no native one (iOS and Android - * hosts draw their own). - */ -export function CanvasGlassButton({onPress, ...props}: CanvasGlassButtonProps) { - if (!NativeGlassButton) return null; - return ; -} diff --git a/src/renderer/CanvasMinimap.tsx b/src/renderer/CanvasMinimap.tsx index 98f83b4..bf16797 100644 --- a/src/renderer/CanvasMinimap.tsx +++ b/src/renderer/CanvasMinimap.tsx @@ -6,7 +6,6 @@ import type {CanvasNode, CanvasEdge} from '../core'; import {getCanvasBackground, getMinimapColors, type ColorScheme} from './theme'; import {hasCssClasses, enrichNodes, type EnrichedNode} from './extensions/cssclasses'; import {recordShapesPicture} from './useCanvasPicture'; -import {CanvasGlass} from './CanvasGlass'; export type MinimapPosition = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'; @@ -27,18 +26,14 @@ interface Props { /** The screen's safe area: the minimap keeps inside it, on every side. */ safeArea?: Insets; /** - * The host's material to sit on, in place of the default: Liquid Glass on - * the Mac (CanvasGlass), a drawn background and border elsewhere. + * The host's material to sit on (its glass, say), in place of the drawn + * background and border: how the minimap looks is the host's. */ background?: (size: {width: number; height: number}) => React.ReactNode; + /** Its corners' radius, in points: the drawn background's, and what clips the host's. */ + cornerRadius?: number; } -/** The Mac's default minimap background: Liquid Glass, as the window's other floating controls. */ -const macGlass = ({width, height}: {width: number; height: number}) => ( - -); -const BORDER_RADIUS_GLASS = 12; - const EDGE_PADDING = 12; const INNER_PADDING = 8; const BORDER_RADIUS = 6; @@ -113,9 +108,9 @@ export function CanvasMinimap({ leftOverlayWidth, bottomInset = 0, safeArea = NO_INSETS, - background: hostBackground, + background, + cornerRadius = BORDER_RADIUS, }: Props) { - const background = hostBackground ?? (Platform.OS === 'macos' ? macGlass : undefined); const bounds = useMemo(() => (nodes.length > 0 ? contentBounds(nodes) : null), [nodes]); const size = useMemo(() => getMinimapSize(bounds ? bounds.width / bounds.height : 1), [bounds]); // Typed rather than inline so a mistyped key fails the build instead of @@ -205,15 +200,15 @@ export function CanvasMinimap({ pointerEvents="none" style={[styles.container, getPositionStyle(position, bottomInset, safeArea), {width: size.width, height: size.height}]} > - {background ? {background(size)} : null} + {background ? {background(size)} : null} {background ? null : ( <> - + @@ -237,9 +232,6 @@ const styles = StyleSheet.create({ container: { position: 'absolute', }, - backgroundMac: { - borderRadius: BORDER_RADIUS_GLASS, - }, background: { borderRadius: BORDER_RADIUS, overflow: 'hidden', diff --git a/src/renderer/CanvasView.tsx b/src/renderer/CanvasView.tsx index 81626c8..5335b37 100644 --- a/src/renderer/CanvasView.tsx +++ b/src/renderer/CanvasView.tsx @@ -133,6 +133,8 @@ interface Props { * minimap's size and drawn behind its content, clipped to its corners. */ minimapBackground?: (size: {width: number; height: number}) => React.ReactNode; + /** The minimap's corner radius, in points (6 by default): its background's, drawn or the host's. */ + minimapCornerRadius?: number; /** * A strip along the view's left edge, in points, where a drag doesn't pan * the canvas but is left to the system: iOS's swipe back, when the canvas @@ -189,7 +191,7 @@ const CAMERA_ANIM_DURATION_MS = 300; * break rendering). Content changes flow through React reconciliation via * useMemo/useLayoutEffect on the content prop. */ -export function CanvasView({content, basePath, initialViewState, onViewStateChange, onReady, doubleTapMaxDelayMs, minimap = 'bottom-right', minimapBottomInset = 0, safeAreaInsets, leftOverlayWidth, minimapBackground, systemEdge = 0}: Props) { +export function CanvasView({content, basePath, initialViewState, onViewStateChange, onReady, doubleTapMaxDelayMs, minimap = 'bottom-right', minimapBottomInset = 0, safeAreaInsets, leftOverlayWidth, minimapBackground, minimapCornerRadius, systemEdge = 0}: Props) { // `useWindowDimensions` returns the whole application window — on desktop // that includes the sidebar pane that sits to the left of the canvas // viewport. Computing "centre" against full-window dimensions lands the @@ -1138,6 +1140,7 @@ export function CanvasView({content, basePath, initialViewState, onViewStateChan bottomInset={minimapBottomInset} safeArea={safeAreaInsets} background={minimapBackground} + cornerRadius={minimapCornerRadius} /> )} diff --git a/src/renderer/index.ts b/src/renderer/index.ts index 6112506..7dbd94e 100644 --- a/src/renderer/index.ts +++ b/src/renderer/index.ts @@ -1,6 +1,5 @@ export {CanvasView} from './CanvasView'; export {CanvasMinimap, type MinimapPosition} from './CanvasMinimap'; -export {CanvasGlass, CanvasGlassButton, type CanvasGlassProps, type CanvasGlassButtonProps} from './CanvasGlass'; export {getNodeColors, resolveScheme, type ColorScheme} from './theme'; export {useCanvasContext, CanvasProvider} from './CanvasContext'; export {activateScrollWheel, deactivateScrollWheel} from './NativeScrollWheelView';