Primitives
The primitives a Soundor plugin UI is made of, from @soundor/react.
@soundor/react renders a plugin's UI with its own components and React Native
conventions, in every runtime: natively, where there is no DOM, and in the
browser. Each page here runs its component live: edit the code, then apply.
import { Pressable, Text, View, useParameter } from '@soundor/react';
import { parameters } from 'soundor:parameters';
// A parameter's value, re-rendered whenever it changes: here, from the
// buttons; in a plugin, from host automation and presets too.
export default function Gain() {
const gain = useParameter(parameters.gain);
const step = (by: number) => parameters.gain.set(gain + by);
return (
<View style={{ alignItems: 'center', gap: 12 }}>
<Text style={{ fontSize: 28, color: '#e6e7ea' }}>
Gain {gain.toFixed(2)}
</Text>
<View style={{ flexDirection: 'row', gap: 8 }}>
{[
{ label: '−', onPress: () => step(-0.1) },
{ label: 'Reset', onPress: () => parameters.gain.set(0.5) },
{ label: '+', onPress: () => step(0.1) },
].map(({ label, onPress }) => (
<Pressable
key={label}
onPress={onPress}
style={({ pressed, hovered }) => ({
minWidth: 44,
alignItems: 'center',
paddingVertical: 8,
paddingHorizontal: 14,
borderRadius: 8,
backgroundColor: pressed
? '#2a5fd0'
: hovered
? '#4f8bff'
: '#3a7bfd',
})}
>
<Text style={{ color: 'white', fontSize: 15 }}>{label}</Text>
</Pressable>
))}
</View>
</View>
);
}gain.tsxSource| Primitive | What it is |
|---|---|
View | A box laid out with flexbox: the building block. |
Text | Text. Every string goes in one. |
Image | A bundled image. |
Svg and shapes | Retained vectors from @soundor/react/svg. |
Pressable | A view that responds to presses, with its state for styling. |
TextInput | A single-line text input. |
Canvas | Pixels code draws, with a 2D or WebGL 2 context. |
Animated.View | A view whose style changes animate. |
Portal | Children rendered elsewhere: over everything, or into a host. |
Modal | A layer over the view that takes its input until it closes. |
FocusScope | A boundary for keyboard focus: trap, autofocus, restore. |
The node components (View, Text, Image, Pressable, TextInput,
Canvas, Animated.View, and the Svg root) take:
style: flexbox layout, spacing, text and paint, as in React Native.StyleSheet.create()names styles with their types.- Event props: Web-style pointer, wheel, key and focus events that capture and bubble as in the DOM.
- Accessibility props: what the component is to a screen reader.
ref: itssoundor:uinode, for its layout, bounds, focus and animations (soundor:ui).
Portal and FocusScope group or place children without exposing these
node props. Modal takes its own dialog props, including backdropStyle and
accessibilityLabel; Portal.Host takes host and style. SVG shapes take
the SVG presentation and geometry props, with input
and accessibility on the Svg root.
Rendering
A plugin's src/main.tsx renders its root component into the plugin view:
import { render } from '@soundor/react';
import { App } from './App';
render(<App />);render(element)renders into the whole plugin view, replacing what it showed, and returns its root.createRoot(node?)makes a root that renders into asoundor:uinode (by default the view's root):{ render(element), unmount() }.flushSync(fn)runsfnand applies the updates it schedules before returning, for code that needs the nodes to be there at once.
The hooks connect components to parameters and frames, and the React UI guide explains how the renderer works.