Skip to main content

Modifiers

In SwiftUI, modifiers wrap a view and return a new view — .padding().background(.blue) builds up styling and behavior. In this renderer, modifiers are factory functions passed as the modifiers prop on any component:

import {
Text,
font,
foregroundColor,
padding,
} from '@appsent-co/react-native-watchos/renderer';

<Text
modifiers={[
font({ style: 'title', weight: 'bold' }),
foregroundColor('accent'),
padding({ horizontal: 12 }),
]}
>
Hello
</Text>;

Order matters — modifiers compose left-to-right, exactly like SwiftUI's chain.

Anatomy of a modifier

Each modifier is a small factory: name(params) → { name, args }. The bridge ships the array to native; the ModifierRegistry resolves each name to its SwiftUI equivalent and applies it.

import { padding } from '@appsent-co/react-native-watchos/renderer';

padding(16); // .padding(16)
padding({ horizontal: 12 }); // .padding(.horizontal, 12)
padding({ top: 8, bottom: 4 });

Number / string / object overloads on a single factory are common — they mirror SwiftUI's overloaded initializers.

Modifier families

The full set is organized into barrels (the index re-exports each export *):

FamilyExamples
Corepadding, frame, font, foregroundColor, background, aspectRatio, resizable, animation, navigationTitle
Layoutframe, position, offset, alignmentGuide, containerRelativeFrame
Stylingbackground, foregroundStyle, border, tint, opacity, clipShape, cornerRadius
Textfont, bold, italic, underline, kerning, lineLimit, multilineTextAlignment
InteractiononTapGesture, onLongPressGesture, disabled, allowsHitTesting
WatchdigitalCrownRotation, sensoryFeedback, containerBackground
NavigationnavigationTitle, navigationBarTitleDisplayMode, toolbar, sheet, fullScreenCover, confirmationDialog, alert
ListslistRowBackground, listRowInsets, listStyle, listSectionSpacing
Component stylesbuttonStyle, toggleStyle, pickerStyle, gaugeStyle, progressViewStyle
InputtextFieldStyle, keyboardType, submitLabel, focused
Image / symbolssymbolRenderingMode, symbolVariant, imageScale, renderingMode
AccessibilityaccessibilityLabel, accessibilityHint, accessibilityValue, accessibilityAddTraits
Filters / transformsblur, brightness, colorMultiply, rotationEffect, scaleEffect
ScrollscrollDisabled, scrollIndicators, scrollPosition, scrollTargetBehavior
PresentationpresentationDetents, presentationCornerRadius, presentationBackground, presentationDragIndicator
GesturesonTapGesture, onLongPressGesture, gesture
Environmentenvironment, preferredColorScheme, colorScheme
GlassglassEffect, glassBackgroundEffect (watchOS 11+)

This is not the complete list — see src/modifiers/ for the canonical, type-safe surface.

Common patterns

Frame

import { frame } from '@appsent-co/react-native-watchos/renderer';

frame({ width: 40, height: 40 });
frame({ maxWidth: 'infinity', alignment: 'leading' });

maxWidth: 'infinity' maps to SwiftUI's .infinity for grow-to-fill layouts.

Background + corner radius

import {
background,
cornerRadius,
} from '@appsent-co/react-native-watchos/renderer';

<VStack
modifiers={[
padding(12),
background('secondary'),
cornerRadius(12),
]}
/>;

Font composition

import { font } from '@appsent-co/react-native-watchos/renderer';

font('title'); // semantic
font(14); // system, 14pt
font({ style: 'body', weight: 'semibold' }); // composed

Digital Crown

import {
digitalCrownRotation,
} from '@appsent-co/react-native-watchos/renderer';

<VStack
modifiers={[
digitalCrownRotation({
value: crown,
from: 0,
through: 100,
onChange: setCrown,
}),
]}
/>;

The crown is the most watch-specific input — see the example app for a worked use.