rnnovaui 0.12.0 → 0.12.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rnnovaui",
3
- "version": "0.12.0",
3
+ "version": "0.12.2",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "react-native": "src/index.js",
@@ -12,6 +12,7 @@ import {
12
12
  Animated as RNAnimated,
13
13
  BackHandler,
14
14
  Dimensions,
15
+ KeyboardAvoidingView,
15
16
  Modal,
16
17
  PanResponder,
17
18
  Platform,
@@ -41,9 +42,7 @@ const { height: SCREEN_HEIGHT } = Dimensions.get("window");
41
42
  /* Helpers */
42
43
  /* -------------------------------------------------------------------------- */
43
44
 
44
- const clamp = (value, min, max) => {
45
- return Math.min(Math.max(value, min), max);
46
- };
45
+ const clamp = (value, min, max) => Math.min(Math.max(value, min), max);
47
46
 
48
47
  const resolveSnapPoint = (point, availableHeight) => {
49
48
  if (typeof point === "number") {
@@ -243,11 +242,15 @@ const UIBottomSheet = forwardRef(function UIBottomSheet(
243
242
  /* Header */
244
243
 
245
244
  header,
245
+
246
246
  title,
247
+
248
+ // NEW
247
249
  titlePosition = "left",
248
250
  titleFontSize = 18,
249
251
  titleColor,
250
252
  titleFontWeight = "700",
253
+
251
254
  titleStyle,
252
255
 
253
256
  showClose = false,
@@ -273,7 +276,7 @@ const UIBottomSheet = forwardRef(function UIBottomSheet(
273
276
 
274
277
  showsVerticalScrollIndicator = false,
275
278
 
276
- /* Safe Area */
279
+ /* Safe area */
277
280
 
278
281
  safeArea = true,
279
282
 
@@ -302,11 +305,15 @@ const UIBottomSheet = forwardRef(function UIBottomSheet(
302
305
  ref,
303
306
  ) {
304
307
  const { theme } = useUITheme();
308
+
305
309
  const insets = useSafeAreaInsets();
306
310
 
307
311
  const colors = theme?.colors ?? {};
312
+
308
313
  const radius = theme?.radius ?? {};
314
+
309
315
  const shadows = theme?.shadows ?? {};
316
+
310
317
  const themeAnimation = theme?.animation ?? {};
311
318
 
312
319
  /* ---------------------------------------------------------------------- */
@@ -322,10 +329,11 @@ const UIBottomSheet = forwardRef(function UIBottomSheet(
322
329
  const [modalVisible, setModalVisible] = useState(isVisible);
323
330
 
324
331
  const mountedRef = useRef(false);
332
+
325
333
  const previousVisibleRef = useRef(isVisible);
326
334
 
327
335
  /* ---------------------------------------------------------------------- */
328
- /* Sheet height */
336
+ /* Height */
329
337
  /* ---------------------------------------------------------------------- */
330
338
 
331
339
  const availableHeight = useMemo(() => {
@@ -381,7 +389,7 @@ const UIBottomSheet = forwardRef(function UIBottomSheet(
381
389
  const backdropProgress = useSharedValue(0);
382
390
 
383
391
  /* ---------------------------------------------------------------------- */
384
- /* Theme */
392
+ /* Colors */
385
393
  /* ---------------------------------------------------------------------- */
386
394
 
387
395
  const resolvedBackground =
@@ -391,12 +399,21 @@ const UIBottomSheet = forwardRef(function UIBottomSheet(
391
399
 
392
400
  const resolvedRadius = borderRadius ?? radius.xl ?? 18;
393
401
 
394
- const resolvedTextColor = colors.text ?? "#111111";
402
+ const resolvedTextColor = titleColor ?? colors.text ?? "#111111";
395
403
 
396
404
  const resolvedCloseColor = closeIconColor ?? colors.text ?? "#111111";
397
405
 
398
406
  /* ---------------------------------------------------------------------- */
399
- /* Visibility callback */
407
+ /* Title position */
408
+ /* ---------------------------------------------------------------------- */
409
+
410
+ const resolvedTitlePosition =
411
+ titlePosition === "center" || titlePosition === "right"
412
+ ? titlePosition
413
+ : "left";
414
+
415
+ /* ---------------------------------------------------------------------- */
416
+ /* Visibility */
400
417
  /* ---------------------------------------------------------------------- */
401
418
 
402
419
  const setVisibility = useCallback(
@@ -413,7 +430,7 @@ const UIBottomSheet = forwardRef(function UIBottomSheet(
413
430
  );
414
431
 
415
432
  /* ---------------------------------------------------------------------- */
416
- /* Native open */
433
+ /* Native OPEN */
417
434
  /* ---------------------------------------------------------------------- */
418
435
 
419
436
  const animateNativeOpen = useCallback(
@@ -427,6 +444,7 @@ const UIBottomSheet = forwardRef(function UIBottomSheet(
427
444
  RNAnimated.parallel([
428
445
  RNAnimated.spring(nativeTranslateY, {
429
446
  toValue: targetTranslate,
447
+
430
448
  useNativeDriver: true,
431
449
 
432
450
  damping: springConfig?.damping ?? 18,
@@ -438,7 +456,9 @@ const UIBottomSheet = forwardRef(function UIBottomSheet(
438
456
 
439
457
  RNAnimated.timing(nativeBackdropOpacity, {
440
458
  toValue: 1,
459
+
441
460
  duration: animationDuration,
461
+
442
462
  useNativeDriver: true,
443
463
  }),
444
464
  ]).start();
@@ -453,34 +473,43 @@ const UIBottomSheet = forwardRef(function UIBottomSheet(
453
473
  );
454
474
 
455
475
  /* ---------------------------------------------------------------------- */
456
- /* Native close */
476
+ /* Native CLOSE */
457
477
  /* ---------------------------------------------------------------------- */
458
478
 
459
- const animateNativeClose = useCallback(
460
- (callback) => {
461
- RNAnimated.parallel([
462
- RNAnimated.timing(nativeTranslateY, {
463
- toValue: SCREEN_HEIGHT,
464
- duration: animationDuration,
465
- useNativeDriver: true,
466
- }),
479
+ const finishClose = useCallback(() => {
480
+ setModalVisible(false);
467
481
 
468
- RNAnimated.timing(nativeBackdropOpacity, {
469
- toValue: 0,
470
- duration: animationDuration,
471
- useNativeDriver: true,
472
- }),
473
- ]).start(({ finished }) => {
474
- if (finished && typeof callback === "function") {
475
- callback();
476
- }
477
- });
478
- },
479
- [nativeTranslateY, nativeBackdropOpacity, animationDuration],
480
- );
482
+ if (typeof onClose === "function") {
483
+ onClose();
484
+ }
485
+ }, [onClose]);
486
+
487
+ const animateNativeClose = useCallback(() => {
488
+ RNAnimated.parallel([
489
+ RNAnimated.timing(nativeTranslateY, {
490
+ toValue: SCREEN_HEIGHT,
491
+
492
+ duration: animationDuration,
493
+
494
+ useNativeDriver: true,
495
+ }),
496
+
497
+ RNAnimated.timing(nativeBackdropOpacity, {
498
+ toValue: 0,
499
+
500
+ duration: animationDuration,
501
+
502
+ useNativeDriver: true,
503
+ }),
504
+ ]).start(({ finished }) => {
505
+ if (finished) {
506
+ finishClose();
507
+ }
508
+ });
509
+ }, [nativeTranslateY, nativeBackdropOpacity, animationDuration, finishClose]);
481
510
 
482
511
  /* ---------------------------------------------------------------------- */
483
- /* Reanimated open */
512
+ /* Reanimated OPEN */
484
513
  /* ---------------------------------------------------------------------- */
485
514
 
486
515
  const animateReanimatedOpen = useCallback(
@@ -511,19 +540,7 @@ const UIBottomSheet = forwardRef(function UIBottomSheet(
511
540
  );
512
541
 
513
542
  /* ---------------------------------------------------------------------- */
514
- /* Finish close */
515
- /* ---------------------------------------------------------------------- */
516
-
517
- const finishClose = useCallback(() => {
518
- setModalVisible(false);
519
-
520
- if (typeof onClose === "function") {
521
- onClose();
522
- }
523
- }, [onClose]);
524
-
525
- /* ---------------------------------------------------------------------- */
526
- /* Reanimated close */
543
+ /* Reanimated CLOSE */
527
544
  /* ---------------------------------------------------------------------- */
528
545
 
529
546
  const animateReanimatedClose = useCallback(() => {
@@ -545,7 +562,7 @@ const UIBottomSheet = forwardRef(function UIBottomSheet(
545
562
  }, [translateY, backdropProgress, animationDuration, finishClose]);
546
563
 
547
564
  /* ---------------------------------------------------------------------- */
548
- /* Animate open */
565
+ /* Open animation */
549
566
  /* ---------------------------------------------------------------------- */
550
567
 
551
568
  const animateOpen = useCallback(
@@ -562,19 +579,19 @@ const UIBottomSheet = forwardRef(function UIBottomSheet(
562
579
  );
563
580
 
564
581
  /* ---------------------------------------------------------------------- */
565
- /* Animate close */
582
+ /* Close animation */
566
583
  /* ---------------------------------------------------------------------- */
567
584
 
568
585
  const animateClose = useCallback(() => {
569
586
  if (reanimated) {
570
587
  animateReanimatedClose();
571
588
  } else {
572
- animateNativeClose(finishClose);
589
+ animateNativeClose();
573
590
  }
574
- }, [reanimated, animateReanimatedClose, animateNativeClose, finishClose]);
591
+ }, [reanimated, animateReanimatedClose, animateNativeClose]);
575
592
 
576
593
  /* ---------------------------------------------------------------------- */
577
- /* Open */
594
+ /* Public OPEN */
578
595
  /* ---------------------------------------------------------------------- */
579
596
 
580
597
  const open = useCallback(
@@ -612,7 +629,7 @@ const UIBottomSheet = forwardRef(function UIBottomSheet(
612
629
  );
613
630
 
614
631
  /* ---------------------------------------------------------------------- */
615
- /* Close */
632
+ /* Public CLOSE */
616
633
  /* ---------------------------------------------------------------------- */
617
634
 
618
635
  const close = useCallback(() => {
@@ -622,6 +639,7 @@ const UIBottomSheet = forwardRef(function UIBottomSheet(
622
639
  }
623
640
 
624
641
  setVisibility(false);
642
+
625
643
  animateClose();
626
644
  }, [modalVisible, setVisibility, animateClose]);
627
645
 
@@ -673,6 +691,7 @@ const UIBottomSheet = forwardRef(function UIBottomSheet(
673
691
  } else {
674
692
  RNAnimated.spring(nativeTranslateY, {
675
693
  toValue: targetTranslate,
694
+
676
695
  useNativeDriver: true,
677
696
 
678
697
  damping: springConfig?.damping ?? 18,
@@ -696,7 +715,7 @@ const UIBottomSheet = forwardRef(function UIBottomSheet(
696
715
  );
697
716
 
698
717
  /* ---------------------------------------------------------------------- */
699
- /* Expand / collapse */
718
+ /* Expand / Collapse */
700
719
  /* ---------------------------------------------------------------------- */
701
720
 
702
721
  const expand = useCallback(() => {
@@ -708,7 +727,7 @@ const UIBottomSheet = forwardRef(function UIBottomSheet(
708
727
  }, [snapTo]);
709
728
 
710
729
  /* ---------------------------------------------------------------------- */
711
- /* Imperative API */
730
+ /* Ref API */
712
731
  /* ---------------------------------------------------------------------- */
713
732
 
714
733
  useImperativeHandle(
@@ -727,7 +746,7 @@ const UIBottomSheet = forwardRef(function UIBottomSheet(
727
746
  );
728
747
 
729
748
  /* ---------------------------------------------------------------------- */
730
- /* Controlled visibility */
749
+ /* Controlled state */
731
750
  /* ---------------------------------------------------------------------- */
732
751
 
733
752
  useEffect(() => {
@@ -751,8 +770,6 @@ const UIBottomSheet = forwardRef(function UIBottomSheet(
751
770
  return undefined;
752
771
  }
753
772
 
754
- /* false -> true */
755
-
756
773
  if (isVisible && !previous) {
757
774
  setModalVisible(true);
758
775
 
@@ -763,8 +780,6 @@ const UIBottomSheet = forwardRef(function UIBottomSheet(
763
780
  return () => clearTimeout(timer);
764
781
  }
765
782
 
766
- /* true -> false */
767
-
768
783
  if (!isVisible && previous) {
769
784
  animateClose();
770
785
  }
@@ -773,7 +788,7 @@ const UIBottomSheet = forwardRef(function UIBottomSheet(
773
788
  }, [isVisible, animateOpen, animateClose]);
774
789
 
775
790
  /* ---------------------------------------------------------------------- */
776
- /* Android back */
791
+ /* Android Back */
777
792
  /* ---------------------------------------------------------------------- */
778
793
 
779
794
  useEffect(() => {
@@ -848,6 +863,7 @@ const UIBottomSheet = forwardRef(function UIBottomSheet(
848
863
 
849
864
  if (distance < nearestDistance) {
850
865
  nearestDistance = distance;
866
+
851
867
  nearestIndex = index;
852
868
  }
853
869
  });
@@ -873,7 +889,7 @@ const UIBottomSheet = forwardRef(function UIBottomSheet(
873
889
  ]);
874
890
 
875
891
  /* ---------------------------------------------------------------------- */
876
- /* Reanimated styles */
892
+ /* Animated styles */
877
893
  /* ---------------------------------------------------------------------- */
878
894
 
879
895
  const animatedSheetStyle = useAnimatedStyle(() => ({
@@ -916,7 +932,6 @@ const UIBottomSheet = forwardRef(function UIBottomSheet(
916
932
 
917
933
  const sheetStyle = [
918
934
  bottomSheetStyles.sheet,
919
-
920
935
  {
921
936
  width,
922
937
  height: finalSheetHeight,
@@ -965,15 +980,29 @@ const UIBottomSheet = forwardRef(function UIBottomSheet(
965
980
  return null;
966
981
  }
967
982
 
968
- return (
969
- <View style={[bottomSheetStyles.header, headerStyle]}>
970
- <View style={bottomSheetStyles.headerTitle}>
983
+ /* -------------------------------------------------------------------- */
984
+ /* CENTER */
985
+ /* -------------------------------------------------------------------- */
986
+
987
+ if (resolvedTitlePosition === "center") {
988
+ return (
989
+ <View
990
+ style={[
991
+ bottomSheetStyles.header,
992
+ bottomSheetStyles.headerCenter,
993
+ headerStyle,
994
+ ]}
995
+ >
971
996
  {typeof title === "string" ? (
972
997
  <Text
998
+ numberOfLines={1}
973
999
  style={[
974
1000
  bottomSheetStyles.title,
1001
+ bottomSheetStyles.titleCenter,
975
1002
  {
1003
+ fontSize: titleFontSize,
976
1004
  color: resolvedTextColor,
1005
+ fontWeight: titleFontWeight,
977
1006
  },
978
1007
  titleStyle,
979
1008
  ]}
@@ -983,7 +1012,71 @@ const UIBottomSheet = forwardRef(function UIBottomSheet(
983
1012
  ) : (
984
1013
  title
985
1014
  )}
1015
+
1016
+ {showClose ? (
1017
+ <Pressable
1018
+ accessibilityRole="button"
1019
+ accessibilityLabel="Close"
1020
+ hitSlop={10}
1021
+ onPress={() => {
1022
+ if (typeof onClosePress === "function") {
1023
+ onClosePress();
1024
+ } else {
1025
+ close();
1026
+ }
1027
+ }}
1028
+ style={[
1029
+ bottomSheetStyles.closeButton,
1030
+ bottomSheetStyles.closeButtonCenter,
1031
+ ]}
1032
+ >
1033
+ <Ionicons
1034
+ name={closeIcon}
1035
+ size={closeIconSize}
1036
+ color={resolvedCloseColor}
1037
+ />
1038
+ </Pressable>
1039
+ ) : null}
986
1040
  </View>
1041
+ );
1042
+ }
1043
+
1044
+ /* -------------------------------------------------------------------- */
1045
+ /* LEFT / RIGHT */
1046
+ /* -------------------------------------------------------------------- */
1047
+
1048
+ return (
1049
+ <View
1050
+ style={[
1051
+ bottomSheetStyles.header,
1052
+ resolvedTitlePosition === "right" && bottomSheetStyles.headerRight,
1053
+ headerStyle,
1054
+ ]}
1055
+ >
1056
+ {typeof title === "string" ? (
1057
+ <Text
1058
+ numberOfLines={1}
1059
+ style={[
1060
+ bottomSheetStyles.title,
1061
+
1062
+ {
1063
+ fontSize: titleFontSize,
1064
+ color: resolvedTextColor,
1065
+ fontWeight: titleFontWeight,
1066
+ },
1067
+
1068
+ resolvedTitlePosition === "right" && {
1069
+ textAlign: "right",
1070
+ },
1071
+
1072
+ titleStyle,
1073
+ ]}
1074
+ >
1075
+ {title}
1076
+ </Text>
1077
+ ) : (
1078
+ title
1079
+ )}
987
1080
 
988
1081
  {showClose ? (
989
1082
  <Pressable
@@ -1011,7 +1104,7 @@ const UIBottomSheet = forwardRef(function UIBottomSheet(
1011
1104
  };
1012
1105
 
1013
1106
  /* ---------------------------------------------------------------------- */
1014
- /* Sheet content */
1107
+ /* Content */
1015
1108
  /* ---------------------------------------------------------------------- */
1016
1109
 
1017
1110
  const sheetContent = (
@@ -1060,7 +1153,7 @@ const UIBottomSheet = forwardRef(function UIBottomSheet(
1060
1153
  );
1061
1154
 
1062
1155
  /* ---------------------------------------------------------------------- */
1063
- /* Backdrop */
1156
+ /* Backdrop press */
1064
1157
  /* ---------------------------------------------------------------------- */
1065
1158
 
1066
1159
  const handleBackdropPress = () => {
@@ -1070,7 +1163,7 @@ const UIBottomSheet = forwardRef(function UIBottomSheet(
1070
1163
  };
1071
1164
 
1072
1165
  /* ---------------------------------------------------------------------- */
1073
- /* Closed */
1166
+ /* Closed */
1074
1167
  /* ---------------------------------------------------------------------- */
1075
1168
 
1076
1169
  if (!modalVisible) {
@@ -1078,7 +1171,7 @@ const UIBottomSheet = forwardRef(function UIBottomSheet(
1078
1171
  }
1079
1172
 
1080
1173
  /* ---------------------------------------------------------------------- */
1081
- /* Render */
1174
+ /* Render */
1082
1175
  /* ---------------------------------------------------------------------- */
1083
1176
 
1084
1177
  return (
@@ -1198,32 +1291,65 @@ const bottomSheetStyles = StyleSheet.create({
1198
1291
  alignSelf: "center",
1199
1292
  },
1200
1293
 
1294
+ /* -------------------------------------------------------------------- */
1295
+ /* Header */
1296
+ /* -------------------------------------------------------------------- */
1297
+
1201
1298
  header: {
1202
1299
  width: "100%",
1203
1300
  minHeight: 50,
1204
1301
  flexDirection: "row",
1205
1302
  alignItems: "center",
1206
- justifyContent: "space-between",
1207
1303
  },
1208
1304
 
1209
- headerTitle: {
1210
- flex: 1,
1305
+ headerCenter: {
1306
+ position: "relative",
1211
1307
  justifyContent: "center",
1212
1308
  },
1213
1309
 
1310
+ headerRight: {
1311
+ justifyContent: "flex-end",
1312
+ },
1313
+
1314
+ /* -------------------------------------------------------------------- */
1315
+ /* Title */
1316
+ /* -------------------------------------------------------------------- */
1317
+
1214
1318
  title: {
1319
+ flex: 1,
1215
1320
  fontSize: 18,
1216
1321
  lineHeight: 24,
1217
1322
  fontWeight: "700",
1218
1323
  },
1219
1324
 
1325
+ titleCenter: {
1326
+ position: "absolute",
1327
+ left: 0,
1328
+ right: 0,
1329
+ textAlign: "center",
1330
+ },
1331
+
1332
+ /* -------------------------------------------------------------------- */
1333
+ /* Close */
1334
+ /* -------------------------------------------------------------------- */
1335
+
1220
1336
  closeButton: {
1221
1337
  width: 44,
1222
1338
  height: 44,
1223
1339
  alignItems: "center",
1224
1340
  justifyContent: "center",
1341
+ zIndex: 10,
1225
1342
  },
1226
1343
 
1344
+ closeButtonCenter: {
1345
+ marginLeft: "auto",
1346
+ zIndex: 20,
1347
+ },
1348
+
1349
+ /* -------------------------------------------------------------------- */
1350
+ /* Content */
1351
+ /* -------------------------------------------------------------------- */
1352
+
1227
1353
  scrollView: {
1228
1354
  flex: 1,
1229
1355
  width: "100%",
@@ -1244,7 +1370,7 @@ const bottomSheetStyles = StyleSheet.create({
1244
1370
  });
1245
1371
 
1246
1372
  /* -------------------------------------------------------------------------- */
1247
- /* Exports */
1373
+ /* Export */
1248
1374
  /* -------------------------------------------------------------------------- */
1249
1375
 
1250
1376
  export { UIBottomSheet };