@interactify-live/player-react-native
Version:
React Native library for Interactify player with media display, widgets, and MQTT integration
62 lines (61 loc) • 2.45 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const react_native_1 = require("react-native");
const WidgetManager = ({ children, style, width, height, enableDrag = false, enableResize = false, enableRotation = false, ...props }) => {
const [widgets, setWidgets] = (0, react_1.useState)(new Map());
const containerRef = (0, react_1.useRef)(null);
const containerStyle = {
position: 'relative',
width: width || '100%',
height: height || '100%',
overflow: 'hidden',
...style,
};
const addWidget = (id, component, zIndex = 1) => {
setWidgets(prev => {
const newWidgets = new Map(prev);
newWidgets.set(id, { id, component, zIndex });
return newWidgets;
});
};
const removeWidget = (id) => {
setWidgets(prev => {
const newWidgets = new Map(prev);
newWidgets.delete(id);
return newWidgets;
});
};
const updateWidget = (id, updates) => {
setWidgets(prev => {
const newWidgets = new Map(prev);
const existing = newWidgets.get(id);
if (existing) {
newWidgets.set(id, { ...existing, ...updates });
}
return newWidgets;
});
};
const clearWidgets = () => {
setWidgets(new Map());
};
const bringToFront = (id) => {
const widget = widgets.get(id);
if (widget) {
const maxZIndex = Math.max(...Array.from(widgets.values()).map(w => w.zIndex));
updateWidget(id, { zIndex: maxZIndex + 1 });
}
};
const sendToBack = (id) => {
const widget = widgets.get(id);
if (widget) {
const minZIndex = Math.min(...Array.from(widgets.values()).map(w => w.zIndex));
updateWidget(id, { zIndex: minZIndex - 1 });
}
};
// Sort widgets by z-index
const sortedWidgets = Array.from(widgets.values()).sort((a, b) => a.zIndex - b.zIndex);
return ((0, jsx_runtime_1.jsxs)(react_native_1.View, { ref: containerRef, style: containerStyle, ...props, children: [children, sortedWidgets.map(widget => ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: { zIndex: widget.zIndex }, children: widget.component }, widget.id)))] }));
};
exports.default = WidgetManager;