aport-tools 4.4.21 → 4.4.23

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/dist/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
- /*! aport-tools v4.4.21 | ISC */
2
- import React, { useContext, useState, createContext, useEffect, useMemo, useCallback } from 'react';
1
+ /*! aport-tools v4.4.23 | ISC */
2
+ import React, { useContext, useState, createContext, useRef, useEffect, useMemo, useCallback } from 'react';
3
3
  import { StyleSheet, Text as Text$1, Animated, View, TouchableOpacity, Image, TextInput, Modal, Pressable, FlatList, Keyboard, Platform, Alert, ActivityIndicator } from 'react-native';
4
4
  import { ThemeContext } from 'aport-themes';
5
5
  import * as ImagePicker from 'expo-image-picker';
@@ -529,15 +529,19 @@ var Input = function Input(_a) {
529
529
  var _c = useState(""),
530
530
  internalValue = _c[0],
531
531
  setInternalValue = _c[1];
532
- // Initialize the internal value based on `firstValue` or `formValues`
532
+ var isFirstRender = useRef(true); // Track the first render
533
+ // Initialize the internal value when `firstValue` changes or on first render
533
534
  useEffect(function () {
534
- if (firstValue) {
535
- setInternalValue(firstValue);
536
- setFormValue(name, firstValue);
537
- } else {
538
- setInternalValue(formValues[name] || "");
535
+ if (isFirstRender.current) {
536
+ isFirstRender.current = false;
537
+ if (firstValue !== undefined) {
538
+ setInternalValue(firstValue);
539
+ setFormValue(name, firstValue);
540
+ } else {
541
+ setInternalValue(formValues[name] || "");
542
+ }
539
543
  }
540
- }, [firstValue, formValues[name]]);
544
+ }, [firstValue]); // Only re-run if `firstValue` changes
541
545
  /**
542
546
  * Handles text changes in the input field, applying formatting based on the inputType.
543
547
  *
@@ -747,73 +751,71 @@ var InputList = function InputList(_a) {
747
751
  var colors = theme.colors;
748
752
  // Initialize selected options based on firstValue
749
753
  // Filter initial selections from options based on `firstValue`
750
- useMemo(function () {
754
+ var initialSelections = useMemo(function () {
751
755
  return options.filter(function (opt) {
752
756
  return firstValue.includes(opt.value);
753
757
  });
754
758
  }, [options, firstValue]);
755
759
  // State for selected options
756
- var _l = useState(multi ? firstValue : firstValue.length > 0 ? firstValue[0] : null),
760
+ var _l = useState(multi ? initialSelections : initialSelections[0] || null),
757
761
  selectedOptions = _l[0],
758
762
  setSelectedOptions = _l[1];
759
763
  // Update form value on mount if firstValue is provided
760
- // Update form value and internal state on mount or `firstValue` change
761
764
  useEffect(function () {
762
- var isDifferent = multi ? Array.isArray(selectedOptions) && (selectedOptions.length !== firstValue.length || !selectedOptions.every(function (opt) {
763
- return firstValue.includes(opt);
764
- })) : selectedOptions !== firstValue[0];
765
- if (firstValue && isDifferent) {
766
- setSelectedOptions(multi ? firstValue : firstValue[0] || null);
765
+ if (firstValue && selectedOptions !== firstValue) {
766
+ setSelectedOptions(firstValue); // Only update if necessary
767
767
  }
768
- }, [firstValue, selectedOptions, multi]);
769
- // Handle option selection
768
+ }, [firstValue, selectedOptions]);
770
769
  var handleSelectOption = function handleSelectOption(option) {
771
770
  var updatedSelections;
772
771
  if (multi) {
773
- var alreadySelected = Array.isArray(selectedOptions) && selectedOptions.some(function (opt) {
772
+ // Ensure selectedOptions is treated as an array
773
+ var selectedArray = Array.isArray(selectedOptions) ? selectedOptions : [];
774
+ var alreadySelected = selectedArray.some(function (opt) {
774
775
  return opt.id === option.id;
775
776
  });
776
- updatedSelections = alreadySelected ? selectedOptions.filter(function (opt) {
777
+ updatedSelections = alreadySelected ? selectedArray.filter(function (opt) {
777
778
  return opt.id !== option.id;
778
- }) : Array.isArray(selectedOptions) ? __spreadArray(__spreadArray([], selectedOptions, true), [option], false) : [option];
779
+ }) : __spreadArray(__spreadArray([], selectedArray, true), [option], false);
779
780
  if (!alreadySelected && maxSelection && updatedSelections.length >= maxSelection) {
780
781
  setIsDropdownVisible(false);
781
782
  }
783
+ setFormValue(name, updatedSelections);
782
784
  } else {
785
+ // Handle single-selection case
783
786
  updatedSelections = option;
787
+ setFormValue(name, option);
784
788
  if (closeOnSelect) setIsDropdownVisible(false);
785
789
  }
786
- setSelectedOptions(updatedSelections);
787
- setFormValue(name, updatedSelections);
790
+ // Trigger onChange callback with the updated selection
788
791
  if (onChange) {
789
792
  onChange(updatedSelections);
790
793
  }
791
794
  };
792
- // Check if an option should be disabled
793
795
  var isItemDisabled = function isItemDisabled(option) {
794
- if (!multi) return false;
795
- return maxSelection && Array.isArray(selectedOptions) && selectedOptions.length >= maxSelection && !selectedOptions.some(function (opt) {
796
+ if (!multi) return false; // Disable check only applies for multi-select
797
+ // Ensure selectedOptions is treated as an array
798
+ var selectedArray = Array.isArray(selectedOptions) ? selectedOptions : [];
799
+ return maxSelection && selectedArray.length >= maxSelection && !selectedArray.some(function (opt) {
796
800
  return opt.id === option.id;
797
801
  });
798
802
  };
799
- // Render selected text
800
803
  var renderSelectedText = function renderSelectedText() {
801
804
  if (multi) {
805
+ // Ensure selectedOptions is treated as an array
802
806
  var selectedArray = Array.isArray(selectedOptions) ? selectedOptions : [];
803
807
  return selectedArray.map(function (opt) {
804
808
  return opt.label;
805
- }).join(", ") || placeholder;
809
+ }).join(', ') || placeholder;
806
810
  }
807
811
  return (selectedOptions === null || selectedOptions === void 0 ? void 0 : selectedOptions.label) || placeholder;
808
812
  };
809
- // Toggle dropdown visibility
810
813
  var toggleDropdown = function toggleDropdown() {
811
814
  if (!disabled) {
812
815
  setIsDropdownVisible(!isDropdownVisible);
813
816
  if (!isDropdownVisible) Keyboard.dismiss();
814
817
  }
815
818
  };
816
- // Close dropdown
817
819
  var handleCloseDropdown = useCallback(function () {
818
820
  if (isDropdownVisible) setIsDropdownVisible(false);
819
821
  }, [isDropdownVisible]);