decord/source/design/components/SegmentedControl/native/SegmentedControl.native.tsx

334 lines
15 KiB
TypeScript
Raw Normal View History

// Module ID: 9863
// Function ID: 9864
2026-07-20 16:05:17 +00:00
// Name: SegmentedControl
// Dependencies: [19, 17, 21, 4605, 576, 4306, 4341, 5024, 9864, 6705, 1115, 2]
2026-07-20 16:05:17 +00:00
// Exports: SegmentedControl
// Module 9863 (SegmentedControl)
import nativeDefault from "native" /* 576 */;
import ReanimatedRexport from "ReanimatedRexport" /* 4341 */;
import spring from "spring" /* 5024 */;
import noop from "module_19" /* 19 */;
2026-07-23 10:11:24 +00:00
require = fn;
get_ActivityIndicator = fn(17);
({ View: closure_4, ScrollView: hasOwnProperty } = get_ActivityIndicator);
const jsxProd = fn(21);
({ jsx: metroRequire, jsxs: closure_7 } = jsxProd);
2026-07-29 08:29:29 +00:00
let c8 = 0.04;
let SELECTED_INDICATOR_SPRING = { mass: 0.3, damping: 13, stiffness: 100, restDisplacementThreshold: 0.001, overshootClamping: true };
const createStyles = fn(4605);
let closure_10 = createStyles.createStyles((borderRadius, paddingVertical) => {
const obj = { scrollContentContainer: { flexGrow: 1 }, controlsContainer: { backgroundColor: nativeDefault.colors.MOBILE_SEGMENTED_CONTROL_BACKGROUND, borderRadius: borderRadius + paddingVertical, paddingVertical, display: "flex", flexDirection: "row", alignItems: "center" }, indicatorContainer: { position: "absolute", width: "100%", height: "100%", borderRadius, flexDirection: "row" }, indicator: null };
const obj2 = { backgroundColor: nativeDefault.colors.MOBILE_SEGMENTED_CONTROL_BACKGROUND, borderRadius: borderRadius + paddingVertical, paddingVertical, display: "flex", flexDirection: "row", alignItems: "center" };
obj.indicator = { flex: 1, backgroundColor: nativeDefault.colors.MOBILE_SEGMENTED_CONTROL_INDICATOR_BACKGROUND, borderRadius };
2026-07-20 16:05:17 +00:00
return obj;
});
2026-07-29 08:29:29 +00:00
let closure_11 = { code: "function SegmentedControlNativeTsx1(){const{indicatorWidth}=this.__closure;return indicatorWidth.get();}" };
let closure_12 = { code: "function SegmentedControlNativeTsx2(_,previous){const{previousIndicatorWidth}=this.__closure;if(previous!=null){previousIndicatorWidth.set(previous);}}" };
let closure_13 = { code: "function SegmentedControlNativeTsx3(){const{activeIndex,itemCount}=this.__closure;return Math.min(Math.max(activeIndex.get(),0),itemCount-1);}" };
let closure_14 = { code: "function SegmentedControlNativeTsx4(){const{clampedActiveIndex,defaultActiveIndex,indicatorWidth}=this.__closure;return(clampedActiveIndex.get()-defaultActiveIndex.get())*indicatorWidth.get();}" };
let closure_15 = { code: "function SegmentedControlNativeTsx5(){const{indicatorTranslateX,pressedIndex,clampedActiveIndex,PRESSED_TRANSLATE_AMOUNT,indicatorWidth,scrollOverflow,interpolate,SCROLL_OVERFLOW_UPPER_BOUND,SCROLL_OVERFLOW_MAX_SCALE,segmentSpacing,itemCount,previousIndicatorWidth,withSpring,SELECTED_INDICATOR_SPRING}=this.__closure;let translateX=indicatorTranslateX.get();let scaleX=1;if(pressedIndex.get()>=0){if(pressedIndex.get()<clampedActiveIndex.get()){scaleX+=PRESSED_TRANSLATE_AMOUNT;translateX-=indicatorWidth.get()*(PRESSED_TRANSLATE_AMOUNT/2);}else if(pressedIndex.get()>clampedActiveIndex.get()){scaleX+=PRESSED_TRANSLATE_AMOUNT;translateX+=indicatorWidth.get()*(PRESSED_TRANSLATE_AMOUNT/2);}}if(scrollOverflow.get()<0){const scaleFactor=interpolate(scrollOverflow.get(),[-SCROLL_OVERFLOW_UPPER_BOUND,0],[SCROLL_OVERFLOW_MAX_SCALE,1],'clamp');const scaleAmount=indicatorWidth.get()*(1-scaleFactor);scaleX=scaleFactor;translateX+=-scaleAmount/2;}else if(scrollOverflow.get()>0){const scaleFactor=interpolate(scrollOverflow.get(),[SCROLL_OVERFLOW_UPPER_BOUND,0],[SCROLL_OVERFLOW_MAX_SCALE,1],'clamp');const scaleAmount=indicatorWidth.get()*(1-scaleFactor);scaleX=scaleFactor;translateX+=scaleAmount/2;}if(clampedActiveIndex.get()===0){translateX+=segmentSpacing;}else if(clampedActiveIndex.get()===itemCount-1){translateX-=segmentSpacing;}const animated=indicatorWidth.get()===previousIndicatorWidth.get();if(!animated){previousIndicatorWidth.set(indicatorWidth.get());}return{transform:[{translateX:animated?withSpring(translateX,SELECTED_INDICATOR_SPRING):translateX},{scaleX:withSpring(scaleX,SELECTED_INDICATOR_SPRING)}]};}" };
let closure_16 = { code: "function onPanGestureUpdate_SegmentedControlNativeTsx6(event){const{indicatorWidth,panIndex,activeIndex,itemCount}=this.__closure;const progess=event.translationX/indicatorWidth.get();const index=panIndex.get()+progess;activeIndex.set(Math.min(Math.max(index,0),itemCount-1));}" };
let closure_17 = { code: "function SegmentedControlNativeTsx7(){const{panIndex,activeIndex,runOnJS,setActiveIndex}=this.__closure;panIndex.set(-1);activeIndex.set(Math.round(activeIndex.get()));runOnJS(setActiveIndex)(activeIndex.get());}" };
let closure_18 = { code: "function SegmentedControlNativeTsx8(){const{panIndex,activeIndex}=this.__closure;panIndex.set(activeIndex.get());}" };
const size = fn(2);
let result = size.fileFinishedImporting("design/components/SegmentedControl/native/SegmentedControl.native.tsx");
2026-07-20 16:05:17 +00:00
2026-07-29 08:29:29 +00:00
export const SegmentedControl = function SegmentedControl(keyboardShouldPersistTaps) {
let state = keyboardShouldPersistTaps.state;
2026-07-29 08:29:29 +00:00
let str = keyboardShouldPersistTaps.variant;
2026-07-20 16:05:17 +00:00
if (str === undefined) {
str = "default";
}
SELECTED_INDICATOR_SPRING = undefined;
2026-07-23 10:11:24 +00:00
let length;
let sharedValue;
let sharedValue1;
let sharedValue2;
__initData = undefined;
2026-07-23 10:11:24 +00:00
let sharedValue3;
let derivedValue;
let derivedValue1;
2026-07-20 16:05:17 +00:00
let animatedStyle;
const activeIndex = state.activeIndex;
const scrollOverflow = state.scrollOverflow;
let items = state.items;
const pressedIndex = state.pressedIndex;
const setActiveIndex = state.setActiveIndex;
closure_7 = tmp;
let num = 4;
2026-07-23 10:11:24 +00:00
if ("experimental_Large" === str) {
2026-07-20 16:05:17 +00:00
num = 8;
}
const tmp4 = length(state(activeIndex[5]).useToken(str(activeIndex[4]).modules.mobile.SEGMENTED_CONTROL_BORDER_RADIUS), num);
SELECTED_INDICATOR_SPRING = tmp4;
2026-07-23 10:11:24 +00:00
length = items.length;
let obj = state(activeIndex[5]);
const tmp2 = state;
let tmp3 = activeIndex;
sharedValue = state(activeIndex[6]).useSharedValue(-1);
2026-07-23 10:11:24 +00:00
let obj2 = state(activeIndex[6]);
sharedValue1 = state(activeIndex[6]).useSharedValue(0);
const obj3 = state(activeIndex[6]);
sharedValue2 = state(activeIndex[6]).useSharedValue(0);
2026-07-23 10:11:24 +00:00
let obj4 = state(activeIndex[6]);
2026-07-20 16:05:17 +00:00
class T {
constructor() {
2026-08-24 06:08:38 +00:00
return closure_12.get();
2026-07-20 16:05:17 +00:00
}
}
T.__closure = { indicatorWidth: sharedValue1 };
T.__workletHash = 5223249035388;
2026-07-29 08:29:29 +00:00
T.__initData = sharedValue;
2026-07-20 16:05:17 +00:00
class R {
constructor(arg0, arg1) {
if (null != arg1) {
2026-08-24 06:08:38 +00:00
tmp = closure_13;
result = closure_13.set(arg1);
2026-07-20 16:05:17 +00:00
}
return;
}
}
R.__closure = { previousIndicatorWidth: sharedValue2 };
R.__workletHash = 14748619096684;
2026-07-29 08:29:29 +00:00
R.__initData = sharedValue1;
const animatedReaction = state(activeIndex[6]).useAnimatedReaction(T, R);
2026-07-29 08:29:29 +00:00
const items1 = [sharedValue1];
__initData = scrollOverflow.useCallback((nativeEvent) => {
2026-07-20 16:05:17 +00:00
const result = sharedValue1.set(nativeEvent.nativeEvent.layout.width);
}, items1);
const obj5 = state(activeIndex[6]);
2026-07-23 10:11:24 +00:00
sharedValue3 = state(activeIndex[6]).useSharedValue(activeIndex.get());
const obj6 = state(activeIndex[6]);
2026-07-20 16:05:17 +00:00
const fn = function k() {
return Math.min(Math.max(activeIndex.get(), 0), length - 1);
};
2026-07-23 10:11:24 +00:00
fn.__closure = { activeIndex, itemCount: length };
2026-07-20 16:05:17 +00:00
fn.__workletHash = 790542357728;
2026-07-29 08:29:29 +00:00
fn.__initData = sharedValue2;
2026-07-23 10:11:24 +00:00
derivedValue = state(activeIndex[6]).useDerivedValue(fn);
2026-07-29 08:29:29 +00:00
const obj7 = state(activeIndex[6]);
2026-07-20 16:05:17 +00:00
class G {
constructor() {
2026-08-24 06:08:38 +00:00
value = closure_16.get();
diff = value - closure_15.get();
return diff * closure_12.get();
2026-07-20 16:05:17 +00:00
}
}
G.__closure = { clampedActiveIndex: derivedValue, defaultActiveIndex: sharedValue3, indicatorWidth: sharedValue1 };
G.__workletHash = 10116271570175;
G.__initData = __initData;
2026-07-23 10:11:24 +00:00
derivedValue1 = state(activeIndex[6]).useDerivedValue(G);
2026-07-29 08:29:29 +00:00
let obj8 = state(activeIndex[6]);
2026-07-20 16:05:17 +00:00
class B {
constructor() {
2026-08-24 06:08:38 +00:00
value = closure_17.get();
2026-07-29 08:29:29 +00:00
obj = pressedIndex;
2026-07-20 16:05:17 +00:00
num = 1;
if (pressedIndex.get() < 0) {
2026-07-29 08:29:29 +00:00
obj3 = scrollOverflow;
2026-07-20 16:05:17 +00:00
if (scrollOverflow.get() < 0) {
tmp11 = closure_0;
tmp12 = closure_2;
obj4 = closure_0(closure_2[6]);
2026-07-20 16:05:17 +00:00
str = "clamp";
2026-07-29 08:29:29 +00:00
tmp13 = obj4;
interpolateResult = obj4.interpolate(obj3.get(), [-50, 0], [0.9, 1], "clamp");
2026-08-24 06:08:38 +00:00
tmp15 = closure_12;
2026-07-29 08:29:29 +00:00
num5 = 2;
2026-08-24 06:08:38 +00:00
sum = value + -closure_12.get() * (1 - interpolateResult) / 2;
2026-07-20 16:05:17 +00:00
num = interpolateResult;
} else {
sum = value;
2026-07-29 08:29:29 +00:00
if (obj3.get() > 0) {
tmp31 = closure_0;
tmp32 = closure_2;
obj13 = closure_0(closure_2[6]);
2026-07-20 16:05:17 +00:00
str2 = "clamp";
2026-07-29 08:29:29 +00:00
tmp33 = obj13;
interpolateResult1 = obj13.interpolate(obj3.get(), [50, 0], [0.9, 1], "clamp");
2026-08-24 06:08:38 +00:00
tmp35 = closure_12;
2026-07-29 08:29:29 +00:00
num6 = 2;
2026-08-24 06:08:38 +00:00
sum = value + closure_12.get() * (1 - interpolateResult1) / 2;
2026-07-20 16:05:17 +00:00
num = interpolateResult1;
}
}
2026-08-24 06:08:38 +00:00
obj5 = closure_16;
if (0 === closure_16.get()) {
2026-07-29 08:29:29 +00:00
tmp20 = c8;
2026-07-23 10:11:24 +00:00
sum1 = sum + c8;
2026-07-20 16:05:17 +00:00
} else {
2026-07-29 08:29:29 +00:00
tmp17 = length;
2026-07-20 16:05:17 +00:00
sum1 = sum;
2026-07-29 08:29:29 +00:00
if (obj5.get() === length - 1) {
tmp19 = c8;
2026-07-23 10:11:24 +00:00
sum1 = sum - c8;
2026-07-20 16:05:17 +00:00
}
}
2026-08-24 06:08:38 +00:00
obj6 = closure_12;
obj7 = closure_13;
value1 = closure_12.get();
tmp22 = value1 === closure_13.get();
2026-07-29 08:29:29 +00:00
if (!tmp22) {
result = obj7.set(obj6.get());
2026-07-20 16:05:17 +00:00
}
withSpringResult = sum1;
2026-07-29 08:29:29 +00:00
if (tmp22) {
tmp25 = closure_0;
tmp26 = closure_2;
obj8 = closure_0(closure_2[7]);
2026-08-24 06:08:38 +00:00
tmp27 = closure_9;
withSpringResult = obj8.withSpring(sum1, closure_9);
2026-07-20 16:05:17 +00:00
}
obj1 = { transform: null };
obj14 = { translateX: null };
obj14.translateX = withSpringResult;
2026-07-29 08:29:29 +00:00
items = [, ];
items[0] = obj14;
obj15 = { scaleX: null };
tmp28 = closure_0;
tmp29 = closure_2;
obj12 = closure_0(closure_2[7]);
2026-08-24 06:08:38 +00:00
tmp30 = closure_9;
obj15.scaleX = obj12.withSpring(num, closure_9);
items[1] = obj15;
obj1.transform = items;
return obj1;
2026-07-20 16:05:17 +00:00
} else {
2026-08-24 06:08:38 +00:00
obj2 = closure_16;
2026-07-29 08:29:29 +00:00
value2 = obj.get();
2026-08-24 06:08:38 +00:00
if (value2 < closure_16.get()) {
2026-07-29 08:29:29 +00:00
tmp7 = c8;
num2 = 1 + c8;
2026-08-24 06:08:38 +00:00
tmp8 = closure_12;
2026-07-20 16:05:17 +00:00
num4 = 0.02;
2026-08-24 06:08:38 +00:00
diff = value - 0.02 * closure_12.get();
2026-07-20 16:05:17 +00:00
} else {
2026-07-29 08:29:29 +00:00
value3 = obj.get();
2026-07-20 16:05:17 +00:00
num2 = 1;
2026-07-29 08:29:29 +00:00
diff = value;
if (value3 > obj2.get()) {
tmp5 = c8;
num2 = 1 + c8;
2026-08-24 06:08:38 +00:00
tmp6 = closure_12;
2026-07-20 16:05:17 +00:00
num3 = 0.02;
2026-08-24 06:08:38 +00:00
diff = value + 0.02 * closure_12.get();
2026-07-20 16:05:17 +00:00
}
}
2026-07-29 08:29:29 +00:00
tmp9 = num2;
tmp10 = diff;
2026-07-20 16:05:17 +00:00
}
return;
}
}
let obj9 = state(activeIndex[6]);
B.__closure = { indicatorTranslateX: derivedValue1, pressedIndex, clampedActiveIndex: derivedValue, PRESSED_TRANSLATE_AMOUNT: num, indicatorWidth: sharedValue1, scrollOverflow, interpolate: state(activeIndex[6]).interpolate, SCROLL_OVERFLOW_UPPER_BOUND: 50, SCROLL_OVERFLOW_MAX_SCALE: 0.9, segmentSpacing: num, itemCount: length, previousIndicatorWidth: sharedValue2, withSpring: state(activeIndex[7]).withSpring, SELECTED_INDICATOR_SPRING };
2026-07-20 16:05:17 +00:00
B.__workletHash = 5537358752627;
2026-07-29 08:29:29 +00:00
B.__initData = sharedValue3;
animatedStyle = obj9.useAnimatedStyle(B);
const items2 = [items, sharedValue3, __initData, tmp4.indicator, animatedStyle];
2026-07-23 10:11:24 +00:00
const items3 = [items, length, num, state, pressedIndex, "experimental_Large" === str, str, setActiveIndex];
const memo = scrollOverflow.useMemo(() => items.map((id, index) => {
const tmp = sharedValue3.get() === index;
let tmp3;
2026-07-20 16:05:17 +00:00
if (tmp) {
tmp3 = __initData;
2026-07-20 16:05:17 +00:00
}
const obj = { onLayout: tmp3, style: null };
items = [indicator.indicator, tmp ? animatedStyle : { opacity: 0 }];
obj.style = items;
return setActiveIndex(str(activeIndex[6]).View, obj, id.id);
2026-07-20 16:05:17 +00:00
}), items2);
2026-07-29 08:29:29 +00:00
function onPanGestureUpdate(translationX) {
const result = translationX.translationX / sharedValue1.get();
const result1 = activeIndex.set(Math.min(Math.max(sharedValue.get() + result, 0), length - 1));
}
onPanGestureUpdate.__closure = { indicatorWidth: sharedValue1, panIndex: sharedValue, activeIndex, itemCount: length };
onPanGestureUpdate.__workletHash = 4853281820821;
onPanGestureUpdate.__initData = derivedValue;
const memo1 = scrollOverflow.useMemo(() => items.map((item, index) => {
state = index;
({ label, id, icon } = item);
2026-07-20 16:05:17 +00:00
if (0 === index) {
2026-07-29 08:29:29 +00:00
let tmp3 = closure_8;
} else if (index === itemCount - 1) {
2026-07-29 08:29:29 +00:00
tmp3 = -closure_8;
2026-07-20 16:05:17 +00:00
}
if (0 === index) {
2026-07-29 08:29:29 +00:00
let tmp6 = -closure_8;
} else if (index === itemCount - 1) {
2026-07-29 08:29:29 +00:00
tmp6 = closure_8;
2026-07-20 16:05:17 +00:00
}
const obj = {
style: { minWidth: `${1 / closure_10 * 100}%`, marginStart: tmp3, marginEnd: tmp6 },
2026-07-20 16:05:17 +00:00
index,
itemCount,
2026-07-20 16:05:17 +00:00
label,
state,
pressed,
2026-07-20 16:05:17 +00:00
onPress() {
setActiveIndex(closure_0);
2026-07-20 16:05:17 +00:00
},
onPressIn() {
const result = pressed.set(closure_0);
2026-07-20 16:05:17 +00:00
},
onPressOut() {
const result = pressed.set(-1);
2026-07-29 08:29:29 +00:00
},
icon: null,
variant: null
2026-07-20 16:05:17 +00:00
};
let tmp9 = null;
2026-07-29 08:29:29 +00:00
if (closure_7) {
2026-07-20 16:05:17 +00:00
tmp9 = icon;
}
obj.icon = tmp9;
obj.variant = variant;
return setActiveIndex(state(activeIndex[8]).SegmentedControlItem, obj, id);
2026-07-20 16:05:17 +00:00
}), items3);
2026-07-23 10:11:24 +00:00
const Gesture = state(activeIndex[9]).Gesture;
let obj10 = { indicatorTranslateX: derivedValue1, pressedIndex, clampedActiveIndex: derivedValue, PRESSED_TRANSLATE_AMOUNT: num, indicatorWidth: sharedValue1, scrollOverflow, interpolate: state(activeIndex[6]).interpolate, SCROLL_OVERFLOW_UPPER_BOUND: 50, SCROLL_OVERFLOW_MAX_SCALE: 0.9, segmentSpacing: num, itemCount: length, previousIndicatorWidth: sharedValue2, withSpring: state(activeIndex[7]).withSpring, SELECTED_INDICATOR_SPRING };
2026-07-20 16:05:17 +00:00
class J {
constructor() {
2026-08-24 06:08:38 +00:00
result = closure_11.set(activeIndex.get());
2026-07-20 16:05:17 +00:00
return;
}
}
J.__closure = { panIndex: sharedValue, activeIndex };
J.__workletHash = 16822477236158;
2026-07-29 08:29:29 +00:00
J.__initData = animatedStyle;
2026-07-20 16:05:17 +00:00
const PanResult = Gesture.Pan();
const onStartResult = Gesture.Pan().onStart(J);
class H {
constructor() {
2026-08-24 06:08:38 +00:00
result = closure_11.set(-1);
2026-07-20 16:05:17 +00:00
result1 = activeIndex.set(Math.round(activeIndex.get()));
obj = closure_0(closure_2[6]);
2026-07-20 16:05:17 +00:00
runOnJSResult = obj.runOnJS(setActiveIndex);
tmp3Result = runOnJSResult(activeIndex.get());
return;
}
}
const onUpdateResult = Gesture.Pan().onStart(J).onUpdate(onPanGestureUpdate);
H.__closure = { panIndex: sharedValue, activeIndex, runOnJS: state(activeIndex[6]).runOnJS, setActiveIndex };
2026-07-20 16:05:17 +00:00
H.__workletHash = 4531135834116;
2026-07-29 08:29:29 +00:00
H.__initData = derivedValue1;
let obj11 = { panIndex: sharedValue, activeIndex, runOnJS: state(activeIndex[6]).runOnJS, setActiveIndex };
const onEndResult = onUpdateResult.onEnd(H);
2026-07-20 16:05:17 +00:00
let str2 = "tabbar";
if (obj15.isAndroid()) {
str2 = "tablist";
}
const obj12 = { accessibilityRole: str2, style: tmp4.controlsContainer, children: null };
const items4 = [setActiveIndex(items, { accessible: false, style: tmp4.indicatorContainer, children: memo }), memo1];
obj12.children = items4;
const tmp18 = closure_7(items, obj12, items.length);
let tmp17Result = setActiveIndex(pressedIndex, { horizontal: true, alwaysBounceHorizontal: false, contentContainerStyle: tmp4.scrollContentContainer, keyboardShouldPersistTaps: keyboardShouldPersistTaps.keyboardShouldPersistTaps, children: tmp18 });
2026-07-23 10:11:24 +00:00
if ("experimental_Large" === str) {
const obj16 = { gesture: onEndResult, children: tmp18 };
tmp17Result = setActiveIndex(tmp2(tmp3[9]).GestureDetector, obj16);
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
return tmp17Result;
2026-07-20 16:05:17 +00:00
};