flowboard-react 0.3.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -0
- package/lib/module/Flowboard.js +47 -9
- package/lib/module/Flowboard.js.map +1 -1
- package/lib/module/components/FlowboardRenderer.js +168 -17
- package/lib/module/components/FlowboardRenderer.js.map +1 -1
- package/lib/module/core/resolverService.js +31 -1
- package/lib/module/core/resolverService.js.map +1 -1
- package/lib/typescript/src/Flowboard.d.ts +5 -1
- package/lib/typescript/src/Flowboard.d.ts.map +1 -1
- package/lib/typescript/src/components/FlowboardRenderer.d.ts.map +1 -1
- package/lib/typescript/src/core/resolverService.d.ts +6 -0
- package/lib/typescript/src/core/resolverService.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/types/flowboard.d.ts +3 -0
- package/lib/typescript/src/types/flowboard.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/Flowboard.ts +81 -14
- package/src/components/FlowboardRenderer.tsx +199 -24
- package/src/core/resolverService.ts +42 -2
- package/src/index.tsx +1 -0
- package/src/types/flowboard.ts +4 -0
package/README.md
CHANGED
|
@@ -74,6 +74,17 @@ await Flowboard.launchOnboarding({
|
|
|
74
74
|
});
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
+
Launch a specific onboarding by ID (without replacing default cached onboarding used by `launchOnboarding`):
|
|
78
|
+
|
|
79
|
+
```tsx
|
|
80
|
+
await Flowboard.launchOnboardingById('YOUR_ONBOARDING_ID', {
|
|
81
|
+
locale: 'fr_FR',
|
|
82
|
+
onOnboardEnd: (formData) => {
|
|
83
|
+
console.log('Specific flow completed:', formData);
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
```
|
|
87
|
+
|
|
77
88
|
Re-initialize:
|
|
78
89
|
|
|
79
90
|
```tsx
|
|
@@ -84,6 +95,7 @@ await Flowboard.reinit();
|
|
|
84
95
|
|
|
85
96
|
- `Flowboard.init({ appId, bundleId, debug, enableAnalytics })`
|
|
86
97
|
- `Flowboard.launchOnboarding({ customScreenBuilder, customActionBuilder, onOnboardEnd, onStepChange, enableAnalytics, alwaysRestart, resumeProgress })`
|
|
98
|
+
- `Flowboard.launchOnboardingById(onboardingId, { locale, customScreenBuilder, customActionBuilder, onOnboardEnd, onStepChange, enableAnalytics, alwaysRestart, resumeProgress })`
|
|
87
99
|
- `Flowboard.reinit()`
|
|
88
100
|
- `FlowboardProvider` (required to host modal flow)
|
|
89
101
|
|
package/lib/module/Flowboard.js
CHANGED
|
@@ -44,15 +44,7 @@ export class Flowboard {
|
|
|
44
44
|
if (!Flowboard.appId) {
|
|
45
45
|
throw new Error('Flowboard.init() must be called before launchOnboarding');
|
|
46
46
|
}
|
|
47
|
-
|
|
48
|
-
const context = AnalyticsManager.instance.clientContextSnapshot ?? (await ClientContext.create());
|
|
49
|
-
AnalyticsManager.instance.configure({
|
|
50
|
-
enabled: options.enableAnalytics ?? true,
|
|
51
|
-
context
|
|
52
|
-
});
|
|
53
|
-
} catch (error) {
|
|
54
|
-
Flowboard.log(`Failed to configure analytics for launch: ${String(error)}`);
|
|
55
|
-
}
|
|
47
|
+
await Flowboard.configureAnalyticsForLaunch(options.enableAnalytics);
|
|
56
48
|
let data = await Flowboard.repository.getOnboardingJson();
|
|
57
49
|
if (!data) {
|
|
58
50
|
Flowboard.log('Data not in cache. Waiting for initialization...');
|
|
@@ -80,6 +72,33 @@ export class Flowboard {
|
|
|
80
72
|
Flowboard.log('Failed to launch: Data is null.');
|
|
81
73
|
return;
|
|
82
74
|
}
|
|
75
|
+
await Flowboard.launchResolvedOnboarding(data, options);
|
|
76
|
+
}
|
|
77
|
+
static async launchOnboardingById(onboardingId, options = {}) {
|
|
78
|
+
Flowboard.log(`Attempting to launch onboarding by id: ${onboardingId}`);
|
|
79
|
+
if (!Flowboard.appId) {
|
|
80
|
+
throw new Error('Flowboard.init() must be called before launchOnboardingById');
|
|
81
|
+
}
|
|
82
|
+
const normalizedOnboardingId = onboardingId.trim();
|
|
83
|
+
if (!normalizedOnboardingId) {
|
|
84
|
+
throw new Error('onboardingId must be a non-empty string');
|
|
85
|
+
}
|
|
86
|
+
await Flowboard.configureAnalyticsForLaunch(options.enableAnalytics);
|
|
87
|
+
const locale = await Flowboard.resolveLocale(options.locale);
|
|
88
|
+
let data;
|
|
89
|
+
try {
|
|
90
|
+
data = await Flowboard.service.fetchOnboardingById({
|
|
91
|
+
onboardingId: normalizedOnboardingId,
|
|
92
|
+
locale
|
|
93
|
+
});
|
|
94
|
+
} catch (error) {
|
|
95
|
+
Flowboard.log(`Failed to load onboarding by id: ${String(error)}`);
|
|
96
|
+
Alert.alert('Failed to load onboarding', String(error));
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
await Flowboard.launchResolvedOnboarding(data, options);
|
|
100
|
+
}
|
|
101
|
+
static async launchResolvedOnboarding(data, options) {
|
|
83
102
|
const shouldResumeProgress = options.resumeProgress === true && options.alwaysRestart !== true;
|
|
84
103
|
if (options.alwaysRestart || !shouldResumeProgress) {
|
|
85
104
|
await Flowboard.repository.clearProgress();
|
|
@@ -113,6 +132,25 @@ export class Flowboard {
|
|
|
113
132
|
initialFormData
|
|
114
133
|
});
|
|
115
134
|
}
|
|
135
|
+
static async configureAnalyticsForLaunch(enableAnalytics) {
|
|
136
|
+
try {
|
|
137
|
+
const context = AnalyticsManager.instance.clientContextSnapshot ?? (await ClientContext.create());
|
|
138
|
+
AnalyticsManager.instance.configure({
|
|
139
|
+
enabled: enableAnalytics ?? true,
|
|
140
|
+
context
|
|
141
|
+
});
|
|
142
|
+
} catch (error) {
|
|
143
|
+
Flowboard.log(`Failed to configure analytics for launch: ${String(error)}`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
static async resolveLocale(requestedLocale) {
|
|
147
|
+
const normalized = requestedLocale?.trim();
|
|
148
|
+
if (normalized) {
|
|
149
|
+
return normalized;
|
|
150
|
+
}
|
|
151
|
+
const context = AnalyticsManager.instance.clientContextSnapshot ?? (await ClientContext.create());
|
|
152
|
+
return context.locale || 'en_US';
|
|
153
|
+
}
|
|
116
154
|
static async initialize() {
|
|
117
155
|
Flowboard.log('Checking local cache...');
|
|
118
156
|
const cached = await Flowboard.repository.getOnboardingJson();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Alert","ClientContext","ResolverService","OnboardingRepository","AnalyticsManager","Flowboard","appId","bundleId","debug","repository","service","initPromise","listeners","Set","subscribe","listener","add","delete","init","params","log","clientContext","create","instance","configure","enabled","enableAnalytics","context","error","String","initialize","reinit","clearLocalCaches","fetchAndSave","launchOnboarding","options","Error","
|
|
1
|
+
{"version":3,"names":["Alert","ClientContext","ResolverService","OnboardingRepository","AnalyticsManager","Flowboard","appId","bundleId","debug","repository","service","initPromise","listeners","Set","subscribe","listener","add","delete","init","params","log","clientContext","create","instance","configure","enabled","enableAnalytics","context","error","String","initialize","reinit","clearLocalCaches","fetchAndSave","launchOnboarding","options","Error","configureAnalyticsForLaunch","data","getOnboardingJson","alert","launchResolvedOnboarding","launchOnboardingById","onboardingId","normalizedOnboardingId","trim","locale","resolveLocale","fetchOnboardingById","shouldResumeProgress","resumeProgress","alwaysRestart","clearProgress","initialStep","initialFormData","flowId","flow_id","savedStep","getProgressStepForFlow","savedFormData","getProgressFormDataForFlow","undefined","screens","Array","isArray","length","maxIndex","Object","keys","emitLaunch","clientContextSnapshot","requestedLocale","normalized","cached","startSession","flowData","startTime","Date","now","installId","json","fetchOnboardingJson","saveOnboardingJson","duration","trackOnboardLoaded","durationMs","Promise","all","clearOnboardingJson","payload","forEach","message","console"],"sourceRoot":"../../src","sources":["Flowboard.ts"],"mappings":";;AAAA,SAASA,KAAK,QAAQ,cAAc;AACpC,SAASC,aAAa,QAAQ,yBAAsB;AACpD,SAASC,eAAe,QAAQ,2BAAwB;AACxD,SAASC,oBAAoB,QAAQ,gCAA6B;AAClE,SAASC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E,CAAC;MACjE,MAAMA,KAAK;IACb;EACF;EAEA,aAAqBI,gBAAgBA,CAAA,EAAkB;IACrD,MAAMsD,OAAO,CAACC,GAAG,CAAC,CAChBlF,SAAS,CAACI,UAAU,CAAC2C,aAAa,CAAC,CAAC,EACpC/C,SAAS,CAACI,UAAU,CAAC+E,mBAAmB,CAAC,CAAC,CAC3C,CAAC;EACJ;EAEA,OAAenB,UAAUA,CAACoB,OAAsB,EAAQ;IACtDpF,SAAS,CAACO,SAAS,CAAC8E,OAAO,CAAE3E,QAAQ,IAAKA,QAAQ,CAAC0E,OAAO,CAAC,CAAC;EAC9D;EAEA,OAAerE,GAAGA,CAACuE,OAAe,EAAQ;IACxC,IAAItF,SAAS,CAACG,KAAK,EAAE;MACnBoF,OAAO,CAACxE,GAAG,CAAC,yBAAyBuE,OAAO,EAAE,CAAC;IACjD;EACF;AACF","ignoreList":[]}
|
|
@@ -1385,6 +1385,9 @@ function WheelPicker({
|
|
|
1385
1385
|
formData,
|
|
1386
1386
|
itemTemplate
|
|
1387
1387
|
}), [formData, itemTemplate, options, properties]);
|
|
1388
|
+
const wheelScrollY = React.useRef(new Animated.Value(0)).current;
|
|
1389
|
+
const wheelScrollRef = React.useRef(null);
|
|
1390
|
+
const lastCommittedWheelValue = React.useRef(null);
|
|
1388
1391
|
const toggleSelection = value => {
|
|
1389
1392
|
setSelectedValues(prev => {
|
|
1390
1393
|
let next = [...prev];
|
|
@@ -1409,6 +1412,53 @@ function WheelPicker({
|
|
|
1409
1412
|
};
|
|
1410
1413
|
const layout = properties.layout ?? 'wheel';
|
|
1411
1414
|
const spacing = Number(properties.spacing ?? 8);
|
|
1415
|
+
const wheelItemHeight = Math.max(1, Number(properties.wheelItemHeight ?? 48));
|
|
1416
|
+
const requestedVisible = Math.max(3, Math.floor(Number(properties.visibleItems ?? 5)));
|
|
1417
|
+
const visibleItems = requestedVisible % 2 === 0 ? requestedVisible + 1 : requestedVisible;
|
|
1418
|
+
const wheelRowStride = wheelItemHeight + Math.max(0, spacing);
|
|
1419
|
+
const wheelContainerHeight = wheelItemHeight * visibleItems;
|
|
1420
|
+
const clampWheelIndex = React.useCallback(index => Math.max(0, Math.min(index, Math.max(0, resolvedOptions.length - 1))), [resolvedOptions.length]);
|
|
1421
|
+
const getWheelSelectedIndex = React.useCallback(() => {
|
|
1422
|
+
if (resolvedOptions.length === 0) return 0;
|
|
1423
|
+
const targetValue = selectedValues[0];
|
|
1424
|
+
if (targetValue === undefined) return 0;
|
|
1425
|
+
const found = resolvedOptions.findIndex(option => String(option.value ?? '') === String(targetValue));
|
|
1426
|
+
return found >= 0 ? found : 0;
|
|
1427
|
+
}, [resolvedOptions, selectedValues]);
|
|
1428
|
+
const commitWheelSelection = React.useCallback(index => {
|
|
1429
|
+
const safeIndex = clampWheelIndex(index);
|
|
1430
|
+
const selectedOption = resolvedOptions[safeIndex];
|
|
1431
|
+
if (!selectedOption) return;
|
|
1432
|
+
const value = String(selectedOption.value ?? '');
|
|
1433
|
+
if (!value) return;
|
|
1434
|
+
setSelectedValues(prev => {
|
|
1435
|
+
if (prev.length === 1 && prev[0] === value) {
|
|
1436
|
+
return prev;
|
|
1437
|
+
}
|
|
1438
|
+
return [value];
|
|
1439
|
+
});
|
|
1440
|
+
if (lastCommittedWheelValue.current !== value) {
|
|
1441
|
+
lastCommittedWheelValue.current = value;
|
|
1442
|
+
onChanged(value);
|
|
1443
|
+
if (properties.autoGoNext === true) {
|
|
1444
|
+
requestAnimationFrame(() => onAction('next', {
|
|
1445
|
+
selectedValue: value
|
|
1446
|
+
}));
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
}, [clampWheelIndex, onAction, onChanged, properties.autoGoNext, resolvedOptions]);
|
|
1450
|
+
React.useEffect(() => {
|
|
1451
|
+
if (layout !== 'wheel' || resolvedOptions.length === 0) return;
|
|
1452
|
+
const selectedIndex = getWheelSelectedIndex();
|
|
1453
|
+
const offsetY = selectedIndex * wheelRowStride;
|
|
1454
|
+
requestAnimationFrame(() => {
|
|
1455
|
+
wheelScrollRef.current?.scrollTo({
|
|
1456
|
+
y: offsetY,
|
|
1457
|
+
animated: false
|
|
1458
|
+
});
|
|
1459
|
+
wheelScrollY.setValue(offsetY);
|
|
1460
|
+
});
|
|
1461
|
+
}, [getWheelSelectedIndex, layout, resolvedOptions.length, wheelRowStride, wheelScrollY]);
|
|
1412
1462
|
const renderItem = (option, index) => {
|
|
1413
1463
|
const value = String(option.value ?? '');
|
|
1414
1464
|
const isSelected = selectedValues.includes(value);
|
|
@@ -1471,29 +1521,130 @@ function WheelPicker({
|
|
|
1471
1521
|
});
|
|
1472
1522
|
}
|
|
1473
1523
|
if (layout === 'wheel') {
|
|
1474
|
-
const
|
|
1475
|
-
const
|
|
1476
|
-
const
|
|
1477
|
-
const
|
|
1478
|
-
const
|
|
1479
|
-
|
|
1524
|
+
const centerPadding = Math.max(0, (wheelContainerHeight - wheelRowStride) / 2);
|
|
1525
|
+
const centerLineTop = (wheelContainerHeight - wheelItemHeight) / 2;
|
|
1526
|
+
const baseUnselectedStyle = properties.unselectedStyle ?? properties.selectedStyle ?? {};
|
|
1527
|
+
const overlayBorderColor = parseColor(properties.wheelCenterBorderColor ?? properties.wheelSelectedBorderColor ?? baseUnselectedStyle.borderColor ?? '#D6D6DC');
|
|
1528
|
+
const overlayBackgroundColor = parseColor(properties.wheelCenterBackgroundColor ?? '#24FFFFFF');
|
|
1529
|
+
const handleWheelMomentumEnd = event => {
|
|
1530
|
+
const offsetY = Number(event?.nativeEvent?.contentOffset?.y ?? 0);
|
|
1531
|
+
const settledIndex = clampWheelIndex(Math.round(offsetY / wheelRowStride));
|
|
1532
|
+
const targetOffset = settledIndex * wheelRowStride;
|
|
1533
|
+
if (Math.abs(targetOffset - offsetY) > 0.5) {
|
|
1534
|
+
wheelScrollRef.current?.scrollTo({
|
|
1535
|
+
y: targetOffset,
|
|
1536
|
+
animated: true
|
|
1537
|
+
});
|
|
1538
|
+
}
|
|
1539
|
+
commitWheelSelection(settledIndex);
|
|
1540
|
+
};
|
|
1541
|
+
return /*#__PURE__*/_jsxs(View, {
|
|
1480
1542
|
style: {
|
|
1481
|
-
height:
|
|
1543
|
+
height: wheelContainerHeight,
|
|
1544
|
+
overflow: 'hidden'
|
|
1482
1545
|
},
|
|
1483
|
-
children: /*#__PURE__*/_jsx(ScrollView, {
|
|
1546
|
+
children: [/*#__PURE__*/_jsx(Animated.ScrollView, {
|
|
1547
|
+
ref: wheelScrollRef,
|
|
1484
1548
|
showsVerticalScrollIndicator: false,
|
|
1549
|
+
bounces: false,
|
|
1550
|
+
decelerationRate: "fast",
|
|
1551
|
+
snapToInterval: wheelRowStride,
|
|
1552
|
+
snapToAlignment: "start",
|
|
1553
|
+
disableIntervalMomentum: false,
|
|
1554
|
+
onMomentumScrollEnd: handleWheelMomentumEnd,
|
|
1485
1555
|
contentContainerStyle: {
|
|
1486
1556
|
paddingVertical: centerPadding
|
|
1487
1557
|
},
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
}
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1558
|
+
onScroll: Animated.event([{
|
|
1559
|
+
nativeEvent: {
|
|
1560
|
+
contentOffset: {
|
|
1561
|
+
y: wheelScrollY
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
}], {
|
|
1565
|
+
useNativeDriver: true
|
|
1566
|
+
}),
|
|
1567
|
+
scrollEventThrottle: 16,
|
|
1568
|
+
children: resolvedOptions.map((option, index) => {
|
|
1569
|
+
const inputRange = [(index - 2) * wheelRowStride, (index - 1) * wheelRowStride, index * wheelRowStride, (index + 1) * wheelRowStride, (index + 2) * wheelRowStride];
|
|
1570
|
+
const opacity = wheelScrollY.interpolate({
|
|
1571
|
+
inputRange,
|
|
1572
|
+
outputRange: [0.35, 0.6, 1, 0.6, 0.35],
|
|
1573
|
+
extrapolate: 'clamp'
|
|
1574
|
+
});
|
|
1575
|
+
const scale = wheelScrollY.interpolate({
|
|
1576
|
+
inputRange,
|
|
1577
|
+
outputRange: [0.82, 0.91, 1, 0.91, 0.82],
|
|
1578
|
+
extrapolate: 'clamp'
|
|
1579
|
+
});
|
|
1580
|
+
const rotateX = wheelScrollY.interpolate({
|
|
1581
|
+
inputRange,
|
|
1582
|
+
outputRange: ['55deg', '28deg', '0deg', '-28deg', '-55deg'],
|
|
1583
|
+
extrapolate: 'clamp'
|
|
1584
|
+
});
|
|
1585
|
+
const translateY = wheelScrollY.interpolate({
|
|
1586
|
+
inputRange,
|
|
1587
|
+
outputRange: [-10, -4, 0, 4, 10],
|
|
1588
|
+
extrapolate: 'clamp'
|
|
1589
|
+
});
|
|
1590
|
+
return /*#__PURE__*/_jsx(Animated.View, {
|
|
1591
|
+
style: {
|
|
1592
|
+
height: wheelRowStride,
|
|
1593
|
+
justifyContent: 'center',
|
|
1594
|
+
opacity,
|
|
1595
|
+
transform: [{
|
|
1596
|
+
perspective: 1200
|
|
1597
|
+
}, {
|
|
1598
|
+
translateY
|
|
1599
|
+
}, {
|
|
1600
|
+
rotateX
|
|
1601
|
+
}, {
|
|
1602
|
+
scale
|
|
1603
|
+
}]
|
|
1604
|
+
},
|
|
1605
|
+
children: /*#__PURE__*/_jsx(View, {
|
|
1606
|
+
style: {
|
|
1607
|
+
minHeight: wheelItemHeight,
|
|
1608
|
+
justifyContent: 'center'
|
|
1609
|
+
},
|
|
1610
|
+
children: renderItem(option, index)
|
|
1611
|
+
})
|
|
1612
|
+
}, `wheel-column-option-${index}`);
|
|
1613
|
+
})
|
|
1614
|
+
}), /*#__PURE__*/_jsx(View, {
|
|
1615
|
+
pointerEvents: "none",
|
|
1616
|
+
style: {
|
|
1617
|
+
position: 'absolute',
|
|
1618
|
+
left: 0,
|
|
1619
|
+
right: 0,
|
|
1620
|
+
top: centerLineTop,
|
|
1621
|
+
height: wheelItemHeight,
|
|
1622
|
+
borderRadius: 14,
|
|
1623
|
+
borderWidth: 1,
|
|
1624
|
+
borderColor: overlayBorderColor,
|
|
1625
|
+
backgroundColor: overlayBackgroundColor
|
|
1626
|
+
}
|
|
1627
|
+
}), /*#__PURE__*/_jsx(LinearGradient, {
|
|
1628
|
+
pointerEvents: "none",
|
|
1629
|
+
colors: ['rgba(255,255,255,0.92)', 'rgba(255,255,255,0)'],
|
|
1630
|
+
style: {
|
|
1631
|
+
position: 'absolute',
|
|
1632
|
+
top: 0,
|
|
1633
|
+
left: 0,
|
|
1634
|
+
right: 0,
|
|
1635
|
+
height: centerPadding
|
|
1636
|
+
}
|
|
1637
|
+
}), /*#__PURE__*/_jsx(LinearGradient, {
|
|
1638
|
+
pointerEvents: "none",
|
|
1639
|
+
colors: ['rgba(255,255,255,0)', 'rgba(255,255,255,0.92)'],
|
|
1640
|
+
style: {
|
|
1641
|
+
position: 'absolute',
|
|
1642
|
+
bottom: 0,
|
|
1643
|
+
left: 0,
|
|
1644
|
+
right: 0,
|
|
1645
|
+
height: centerPadding
|
|
1646
|
+
}
|
|
1647
|
+
})]
|
|
1497
1648
|
});
|
|
1498
1649
|
}
|
|
1499
1650
|
return /*#__PURE__*/_jsx(View, {
|