@terreno/ui 0.0.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/LICENSE +203 -0
- package/README.md +160 -0
- package/dist/Accordion.d.ts +3 -0
- package/dist/Accordion.js +30 -0
- package/dist/Accordion.js.map +1 -0
- package/dist/ActionSheet.d.ts +169 -0
- package/dist/ActionSheet.js +637 -0
- package/dist/ActionSheet.js.map +1 -0
- package/dist/AddressField.d.ts +3 -0
- package/dist/AddressField.js +18 -0
- package/dist/AddressField.js.map +1 -0
- package/dist/Avatar.d.ts +3 -0
- package/dist/Avatar.js +189 -0
- package/dist/Avatar.js.map +1 -0
- package/dist/Badge.d.ts +3 -0
- package/dist/Badge.js +100 -0
- package/dist/Badge.js.map +1 -0
- package/dist/Banner.d.ts +4 -0
- package/dist/Banner.js +103 -0
- package/dist/Banner.js.map +1 -0
- package/dist/Body.d.ts +3 -0
- package/dist/Body.js +17 -0
- package/dist/Body.js.map +1 -0
- package/dist/BooleanField.d.ts +3 -0
- package/dist/BooleanField.js +89 -0
- package/dist/BooleanField.js.map +1 -0
- package/dist/Box.d.ts +3 -0
- package/dist/Box.js +289 -0
- package/dist/Box.js.map +1 -0
- package/dist/Button.d.ts +3 -0
- package/dist/Button.js +105 -0
- package/dist/Button.js.map +1 -0
- package/dist/Card.d.ts +2 -0
- package/dist/Card.js +18 -0
- package/dist/Card.js.map +1 -0
- package/dist/CheckBox.d.ts +3 -0
- package/dist/CheckBox.js +28 -0
- package/dist/CheckBox.js.map +1 -0
- package/dist/Common.d.ts +2325 -0
- package/dist/Common.js +47 -0
- package/dist/Common.js.map +1 -0
- package/dist/CommonIconTypes.d.ts +3 -0
- package/dist/CommonIconTypes.js +2 -0
- package/dist/CommonIconTypes.js.map +1 -0
- package/dist/Constants.d.ts +12685 -0
- package/dist/Constants.js +3310 -0
- package/dist/Constants.js.map +1 -0
- package/dist/CustomSelectField.d.ts +3 -0
- package/dist/CustomSelectField.js +59 -0
- package/dist/CustomSelectField.js.map +1 -0
- package/dist/DataTable.d.ts +3 -0
- package/dist/DataTable.js +190 -0
- package/dist/DataTable.js.map +1 -0
- package/dist/DateTimeActionSheet.d.ts +2 -0
- package/dist/DateTimeActionSheet.js +270 -0
- package/dist/DateTimeActionSheet.js.map +1 -0
- package/dist/DateTimeField.d.ts +3 -0
- package/dist/DateTimeField.js +514 -0
- package/dist/DateTimeField.js.map +1 -0
- package/dist/DateUtilities.d.ts +57 -0
- package/dist/DateUtilities.js +308 -0
- package/dist/DateUtilities.js.map +1 -0
- package/dist/DecimalRangeActionSheet.d.ts +6 -0
- package/dist/DecimalRangeActionSheet.js +45 -0
- package/dist/DecimalRangeActionSheet.js.map +1 -0
- package/dist/DismissButton.d.ts +3 -0
- package/dist/DismissButton.js +12 -0
- package/dist/DismissButton.js.map +1 -0
- package/dist/EmailField.d.ts +3 -0
- package/dist/EmailField.js +48 -0
- package/dist/EmailField.js.map +1 -0
- package/dist/EmojiSelector.d.ts +113 -0
- package/dist/EmojiSelector.js +322 -0
- package/dist/EmojiSelector.js.map +1 -0
- package/dist/ErrorBoundary.d.ts +19 -0
- package/dist/ErrorBoundary.js +30 -0
- package/dist/ErrorBoundary.js.map +1 -0
- package/dist/ErrorPage.d.ts +6 -0
- package/dist/ErrorPage.js +15 -0
- package/dist/ErrorPage.js.map +1 -0
- package/dist/Field.d.ts +3 -0
- package/dist/Field.js +80 -0
- package/dist/Field.js.map +1 -0
- package/dist/FlatList.d.ts +2 -0
- package/dist/FlatList.js +3 -0
- package/dist/FlatList.js.map +1 -0
- package/dist/Heading.d.ts +3 -0
- package/dist/Heading.js +43 -0
- package/dist/Heading.js.map +1 -0
- package/dist/HeightActionSheet.d.ts +11 -0
- package/dist/HeightActionSheet.js +46 -0
- package/dist/HeightActionSheet.js.map +1 -0
- package/dist/Hyperlink.d.ts +30 -0
- package/dist/Hyperlink.js +144 -0
- package/dist/Hyperlink.js.map +1 -0
- package/dist/Icon.d.ts +3 -0
- package/dist/Icon.js +15 -0
- package/dist/Icon.js.map +1 -0
- package/dist/IconButton.d.ts +3 -0
- package/dist/IconButton.js +111 -0
- package/dist/IconButton.js.map +1 -0
- package/dist/Image.d.ts +8 -0
- package/dist/Image.js +37 -0
- package/dist/Image.js.map +1 -0
- package/dist/ImageBackground.d.ts +10 -0
- package/dist/ImageBackground.js +9 -0
- package/dist/ImageBackground.js.map +1 -0
- package/dist/InfoModalIcon.d.ts +3 -0
- package/dist/InfoModalIcon.js +10 -0
- package/dist/InfoModalIcon.js.map +1 -0
- package/dist/InfoTooltipButton.d.ts +3 -0
- package/dist/InfoTooltipButton.js +6 -0
- package/dist/InfoTooltipButton.js.map +1 -0
- package/dist/Link.d.ts +3 -0
- package/dist/Link.js +10 -0
- package/dist/Link.js.map +1 -0
- package/dist/MarkdownView.d.ts +5 -0
- package/dist/MarkdownView.js +44 -0
- package/dist/MarkdownView.js.map +1 -0
- package/dist/MediaQuery.d.ts +4 -0
- package/dist/MediaQuery.js +52 -0
- package/dist/MediaQuery.js.map +1 -0
- package/dist/MobileAddressAutoComplete.d.ts +2 -0
- package/dist/MobileAddressAutoComplete.js +54 -0
- package/dist/MobileAddressAutoComplete.js.map +1 -0
- package/dist/Modal.d.ts +3 -0
- package/dist/Modal.js +127 -0
- package/dist/Modal.js.map +1 -0
- package/dist/ModalSheet.d.ts +6 -0
- package/dist/ModalSheet.js +42 -0
- package/dist/ModalSheet.js.map +1 -0
- package/dist/MultiselectField.d.ts +3 -0
- package/dist/MultiselectField.js +45 -0
- package/dist/MultiselectField.js.map +1 -0
- package/dist/NumberField.d.ts +3 -0
- package/dist/NumberField.js +60 -0
- package/dist/NumberField.js.map +1 -0
- package/dist/NumberPickerActionSheet.d.ts +7 -0
- package/dist/NumberPickerActionSheet.js +22 -0
- package/dist/NumberPickerActionSheet.js.map +1 -0
- package/dist/OpenAPIContext.d.ts +4 -0
- package/dist/OpenAPIContext.js +53 -0
- package/dist/OpenAPIContext.js.map +1 -0
- package/dist/Page.d.ts +7 -0
- package/dist/Page.js +24 -0
- package/dist/Page.js.map +1 -0
- package/dist/Pagination.d.ts +3 -0
- package/dist/Pagination.js +106 -0
- package/dist/Pagination.js.map +1 -0
- package/dist/PasswordField.d.ts +2 -0
- package/dist/PasswordField.js +6 -0
- package/dist/PasswordField.js.map +1 -0
- package/dist/Permissions.d.ts +2 -0
- package/dist/Permissions.js +35 -0
- package/dist/Permissions.js.map +1 -0
- package/dist/PhoneNumberField.d.ts +3 -0
- package/dist/PhoneNumberField.js +83 -0
- package/dist/PhoneNumberField.js.map +1 -0
- package/dist/PickerSelect.d.ts +46 -0
- package/dist/PickerSelect.js +306 -0
- package/dist/PickerSelect.js.map +1 -0
- package/dist/Radio.d.ts +3 -0
- package/dist/Radio.js +21 -0
- package/dist/Radio.js.map +1 -0
- package/dist/RadioField.d.ts +3 -0
- package/dist/RadioField.js +16 -0
- package/dist/RadioField.js.map +1 -0
- package/dist/ScrollView.d.ts +2 -0
- package/dist/ScrollView.js +3 -0
- package/dist/ScrollView.js.map +1 -0
- package/dist/SectionDivider.d.ts +2 -0
- package/dist/SectionDivider.js +12 -0
- package/dist/SectionDivider.js.map +1 -0
- package/dist/SegmentedControl.d.ts +3 -0
- package/dist/SegmentedControl.js +65 -0
- package/dist/SegmentedControl.js.map +1 -0
- package/dist/SelectBadge.d.ts +3 -0
- package/dist/SelectBadge.js +166 -0
- package/dist/SelectBadge.js.map +1 -0
- package/dist/SelectField.d.ts +3 -0
- package/dist/SelectField.js +16 -0
- package/dist/SelectField.js.map +1 -0
- package/dist/SideDrawer.d.ts +3 -0
- package/dist/SideDrawer.js +32 -0
- package/dist/SideDrawer.js.map +1 -0
- package/dist/Signature.d.ts +8 -0
- package/dist/Signature.js +21 -0
- package/dist/Signature.js.map +1 -0
- package/dist/Signature.native.d.ts +8 -0
- package/dist/Signature.native.js +26 -0
- package/dist/Signature.native.js.map +1 -0
- package/dist/SignatureField.d.ts +3 -0
- package/dist/SignatureField.js +42 -0
- package/dist/SignatureField.js.map +1 -0
- package/dist/Slider.d.ts +3 -0
- package/dist/Slider.js +78 -0
- package/dist/Slider.js.map +1 -0
- package/dist/Spinner.d.ts +3 -0
- package/dist/Spinner.js +33 -0
- package/dist/Spinner.js.map +1 -0
- package/dist/SplitPage.d.ts +2 -0
- package/dist/SplitPage.js +139 -0
- package/dist/SplitPage.js.map +1 -0
- package/dist/SplitPage.native.d.ts +2 -0
- package/dist/SplitPage.native.js +75 -0
- package/dist/SplitPage.native.js.map +1 -0
- package/dist/TapToEdit.d.ts +4 -0
- package/dist/TapToEdit.js +170 -0
- package/dist/TapToEdit.js.map +1 -0
- package/dist/TerrenoProvider.d.ts +6 -0
- package/dist/TerrenoProvider.js +10 -0
- package/dist/TerrenoProvider.js.map +1 -0
- package/dist/Text.d.ts +3 -0
- package/dist/Text.js +95 -0
- package/dist/Text.js.map +1 -0
- package/dist/TextArea.d.ts +3 -0
- package/dist/TextArea.js +6 -0
- package/dist/TextArea.js.map +1 -0
- package/dist/TextField.d.ts +3 -0
- package/dist/TextField.js +144 -0
- package/dist/TextField.js.map +1 -0
- package/dist/TextFieldNumberActionSheet.d.ts +7 -0
- package/dist/TextFieldNumberActionSheet.js +20 -0
- package/dist/TextFieldNumberActionSheet.js.map +1 -0
- package/dist/Theme.d.ts +96 -0
- package/dist/Theme.js +213 -0
- package/dist/Theme.js.map +1 -0
- package/dist/TimezonePicker.d.ts +11 -0
- package/dist/TimezonePicker.js +27 -0
- package/dist/TimezonePicker.js.map +1 -0
- package/dist/Toast.d.ts +23 -0
- package/dist/Toast.js +157 -0
- package/dist/Toast.js.map +1 -0
- package/dist/Tooltip.d.ts +3 -0
- package/dist/Tooltip.js +289 -0
- package/dist/Tooltip.js.map +1 -0
- package/dist/UnifiedAddressAutoComplete.d.ts +2 -0
- package/dist/UnifiedAddressAutoComplete.js +23 -0
- package/dist/UnifiedAddressAutoComplete.js.map +1 -0
- package/dist/Unifier.d.ts +43 -0
- package/dist/Unifier.js +154 -0
- package/dist/Unifier.js.map +1 -0
- package/dist/Utilities.d.ts +56 -0
- package/dist/Utilities.js +193 -0
- package/dist/Utilities.js.map +1 -0
- package/dist/WebAddressAutocomplete.d.ts +3 -0
- package/dist/WebAddressAutocomplete.js +61 -0
- package/dist/WebAddressAutocomplete.js.map +1 -0
- package/dist/fieldElements/FieldError.d.ts +6 -0
- package/dist/fieldElements/FieldError.js +9 -0
- package/dist/fieldElements/FieldError.js.map +1 -0
- package/dist/fieldElements/FieldHelperText.d.ts +6 -0
- package/dist/fieldElements/FieldHelperText.js +8 -0
- package/dist/fieldElements/FieldHelperText.js.map +1 -0
- package/dist/fieldElements/FieldTitle.d.ts +6 -0
- package/dist/fieldElements/FieldTitle.js +16 -0
- package/dist/fieldElements/FieldTitle.js.map +1 -0
- package/dist/fieldElements/index.d.ts +3 -0
- package/dist/fieldElements/index.js +4 -0
- package/dist/fieldElements/index.js.map +1 -0
- package/dist/icons/MobileIcon.d.ts +2 -0
- package/dist/icons/MobileIcon.js +18 -0
- package/dist/icons/MobileIcon.js.map +1 -0
- package/dist/icons/OfflineIcon.d.ts +2 -0
- package/dist/icons/OfflineIcon.js +18 -0
- package/dist/icons/OfflineIcon.js.map +1 -0
- package/dist/icons/OnlineIcon.d.ts +2 -0
- package/dist/icons/OnlineIcon.js +19 -0
- package/dist/icons/OnlineIcon.js.map +1 -0
- package/dist/icons/OutOfficeIcon.d.ts +2 -0
- package/dist/icons/OutOfficeIcon.js +18 -0
- package/dist/icons/OutOfficeIcon.js.map +1 -0
- package/dist/icons/index.d.ts +4 -0
- package/dist/icons/index.js +5 -0
- package/dist/icons/index.js.map +1 -0
- package/dist/index.d.ts +1328 -0
- package/dist/index.js +89 -0
- package/dist/index.js.map +1 -0
- package/dist/table/Table.d.ts +3 -0
- package/dist/table/Table.js +53 -0
- package/dist/table/Table.js.map +1 -0
- package/dist/table/TableBadge.d.ts +6 -0
- package/dist/table/TableBadge.js +23 -0
- package/dist/table/TableBadge.js.map +1 -0
- package/dist/table/TableBoolean.d.ts +6 -0
- package/dist/table/TableBoolean.js +37 -0
- package/dist/table/TableBoolean.js.map +1 -0
- package/dist/table/TableDate.d.ts +3 -0
- package/dist/table/TableDate.js +27 -0
- package/dist/table/TableDate.js.map +1 -0
- package/dist/table/TableHeader.d.ts +6 -0
- package/dist/table/TableHeader.js +10 -0
- package/dist/table/TableHeader.js.map +1 -0
- package/dist/table/TableHeaderCell.d.ts +6 -0
- package/dist/table/TableHeaderCell.js +54 -0
- package/dist/table/TableHeaderCell.js.map +1 -0
- package/dist/table/TableIconButton.d.ts +3 -0
- package/dist/table/TableIconButton.js +39 -0
- package/dist/table/TableIconButton.js.map +1 -0
- package/dist/table/TableNumber.d.ts +3 -0
- package/dist/table/TableNumber.js +18 -0
- package/dist/table/TableNumber.js.map +1 -0
- package/dist/table/TableRow.d.ts +6 -0
- package/dist/table/TableRow.js +22 -0
- package/dist/table/TableRow.js.map +1 -0
- package/dist/table/TableText.d.ts +3 -0
- package/dist/table/TableText.js +18 -0
- package/dist/table/TableText.js.map +1 -0
- package/dist/table/TableTitle.d.ts +3 -0
- package/dist/table/TableTitle.js +21 -0
- package/dist/table/TableTitle.js.map +1 -0
- package/dist/table/tableContext.d.ts +5 -0
- package/dist/table/tableContext.js +38 -0
- package/dist/table/tableContext.js.map +1 -0
- package/dist/useStoredState.d.ts +1 -0
- package/dist/useStoredState.js +49 -0
- package/dist/useStoredState.js.map +1 -0
- package/package.json +123 -0
- package/src/Accordion.test.tsx +104 -0
- package/src/Accordion.tsx +81 -0
- package/src/ActionSheet.tsx +881 -0
- package/src/AddressField.test.tsx +120 -0
- package/src/AddressField.tsx +122 -0
- package/src/Avatar.test.tsx +163 -0
- package/src/Avatar.tsx +298 -0
- package/src/Badge.test.tsx +116 -0
- package/src/Badge.tsx +136 -0
- package/src/Banner.tsx +200 -0
- package/src/Body.tsx +34 -0
- package/src/BooleanField.tsx +141 -0
- package/src/Box.test.tsx +662 -0
- package/src/Box.tsx +368 -0
- package/src/Button.tsx +196 -0
- package/src/Card.tsx +19 -0
- package/src/CheckBox.tsx +45 -0
- package/src/Common.ts +2787 -0
- package/src/CommonIconTypes.ts +2030 -0
- package/src/Constants.ts +3311 -0
- package/src/CustomSelectField.tsx +115 -0
- package/src/DataTable.tsx +674 -0
- package/src/DateTimeActionSheet.tsx +559 -0
- package/src/DateTimeField.test.tsx +393 -0
- package/src/DateTimeField.tsx +777 -0
- package/src/DateUtilities.test.ts +440 -0
- package/src/DateUtilities.tsx +370 -0
- package/src/DecimalRangeActionSheet.tsx +85 -0
- package/src/DismissButton.tsx +31 -0
- package/src/EmailField.tsx +66 -0
- package/src/EmojiSelector.test.tsx +61 -0
- package/src/EmojiSelector.tsx +510 -0
- package/src/ErrorBoundary.tsx +37 -0
- package/src/ErrorPage.tsx +41 -0
- package/src/Field.tsx +101 -0
- package/src/FlatList.tsx +2 -0
- package/src/Heading.tsx +66 -0
- package/src/HeightActionSheet.tsx +91 -0
- package/src/Hyperlink.tsx +179 -0
- package/src/Icon.tsx +36 -0
- package/src/IconButton.tsx +217 -0
- package/src/Image.tsx +51 -0
- package/src/ImageBackground.tsx +14 -0
- package/src/InfoModalIcon.tsx +42 -0
- package/src/InfoTooltipButton.tsx +16 -0
- package/src/Link.tsx +22 -0
- package/src/MarkdownView.tsx +67 -0
- package/src/MediaQuery.ts +46 -0
- package/src/MobileAddressAutoComplete.tsx +126 -0
- package/src/Modal.tsx +300 -0
- package/src/ModalSheet.tsx +58 -0
- package/src/MultiselectField.tsx +112 -0
- package/src/NumberField.tsx +67 -0
- package/src/NumberPickerActionSheet.tsx +51 -0
- package/src/OpenAPIContext.tsx +74 -0
- package/src/Page.tsx +105 -0
- package/src/Pagination.tsx +169 -0
- package/src/PasswordField.tsx +7 -0
- package/src/Permissions.ts +43 -0
- package/src/PhoneNumberField.tsx +109 -0
- package/src/PickerSelect.tsx +571 -0
- package/src/Radio.tsx +33 -0
- package/src/RadioField.tsx +43 -0
- package/src/ScrollView.tsx +2 -0
- package/src/SectionDivider.tsx +18 -0
- package/src/SegmentedControl.tsx +126 -0
- package/src/SelectBadge.tsx +280 -0
- package/src/SelectField.tsx +41 -0
- package/src/SideDrawer.tsx +56 -0
- package/src/Signature.native.tsx +57 -0
- package/src/Signature.tsx +44 -0
- package/src/SignatureField.tsx +92 -0
- package/src/Slider.tsx +199 -0
- package/src/Spinner.tsx +35 -0
- package/src/SplitPage.native.tsx +163 -0
- package/src/SplitPage.tsx +304 -0
- package/src/TapToEdit.tsx +292 -0
- package/src/TerrenoProvider.tsx +31 -0
- package/src/Text.tsx +123 -0
- package/src/TextArea.test.tsx +255 -0
- package/src/TextArea.tsx +8 -0
- package/src/TextField.test.tsx +487 -0
- package/src/TextField.tsx +260 -0
- package/src/TextFieldNumberActionSheet.tsx +46 -0
- package/src/Theme.tsx +248 -0
- package/src/TimezonePicker.tsx +45 -0
- package/src/Toast.tsx +234 -0
- package/src/Tooltip.tsx +407 -0
- package/src/UnifiedAddressAutoComplete.tsx +66 -0
- package/src/Unifier.ts +172 -0
- package/src/Utilities.tsx +329 -0
- package/src/WebAddressAutocomplete.tsx +84 -0
- package/src/__snapshots__/Accordion.test.tsx.snap +126 -0
- package/src/__snapshots__/AddressField.test.tsx.snap +1197 -0
- package/src/__snapshots__/Avatar.test.tsx.snap +57 -0
- package/src/__snapshots__/Badge.test.tsx.snap +55 -0
- package/src/__snapshots__/Box.test.tsx.snap +162 -0
- package/src/__snapshots__/EmojiSelector.test.tsx.snap +422 -0
- package/src/__snapshots__/TextArea.test.tsx.snap +521 -0
- package/src/__snapshots__/TextField.test.tsx.snap +569 -0
- package/src/bunSetup.ts +1235 -0
- package/src/fieldElements/FieldError.tsx +24 -0
- package/src/fieldElements/FieldHelperText.tsx +20 -0
- package/src/fieldElements/FieldTitle.tsx +31 -0
- package/src/fieldElements/index.tsx +3 -0
- package/src/icons/MobileIcon.tsx +40 -0
- package/src/icons/OfflineIcon.tsx +37 -0
- package/src/icons/OnlineIcon.tsx +39 -0
- package/src/icons/OutOfficeIcon.tsx +36 -0
- package/src/icons/index.ts +4 -0
- package/src/index.tsx +1375 -0
- package/src/polyfill.d.ts +11 -0
- package/src/table/Table.tsx +109 -0
- package/src/table/TableBadge.tsx +46 -0
- package/src/table/TableBoolean.tsx +70 -0
- package/src/table/TableDate.tsx +38 -0
- package/src/table/TableHeader.tsx +20 -0
- package/src/table/TableHeaderCell.tsx +94 -0
- package/src/table/TableIconButton.tsx +61 -0
- package/src/table/TableNumber.tsx +29 -0
- package/src/table/TableRow.tsx +67 -0
- package/src/table/TableText.tsx +29 -0
- package/src/table/TableTitle.tsx +31 -0
- package/src/table/tableContext.tsx +67 -0
- package/src/test-utils.tsx +27 -0
- package/src/types/react-native-swiper-flatlist.d.ts +56 -0
- package/src/useStoredState.test.tsx +143 -0
- package/src/useStoredState.ts +56 -0
|
@@ -0,0 +1,881 @@
|
|
|
1
|
+
import type React from "react";
|
|
2
|
+
import {Component, createRef} from "react";
|
|
3
|
+
import {
|
|
4
|
+
Animated,
|
|
5
|
+
Dimensions,
|
|
6
|
+
type EmitterSubscription,
|
|
7
|
+
FlatList,
|
|
8
|
+
findNodeHandle,
|
|
9
|
+
Keyboard,
|
|
10
|
+
type KeyboardEvent,
|
|
11
|
+
type LayoutChangeEvent,
|
|
12
|
+
Modal,
|
|
13
|
+
type NativeScrollEvent,
|
|
14
|
+
type NativeSyntheticEvent,
|
|
15
|
+
Platform,
|
|
16
|
+
Pressable,
|
|
17
|
+
SafeAreaView,
|
|
18
|
+
StatusBar,
|
|
19
|
+
StyleSheet,
|
|
20
|
+
TextInput,
|
|
21
|
+
UIManager,
|
|
22
|
+
View,
|
|
23
|
+
} from "react-native";
|
|
24
|
+
|
|
25
|
+
import type {ActionSheetProps} from "./Common";
|
|
26
|
+
|
|
27
|
+
export const styles = StyleSheet.create({
|
|
28
|
+
container: {
|
|
29
|
+
alignSelf: "center",
|
|
30
|
+
backgroundColor: "white",
|
|
31
|
+
width: "100%",
|
|
32
|
+
},
|
|
33
|
+
indicator: {
|
|
34
|
+
alignSelf: "center",
|
|
35
|
+
backgroundColor: "#f0f0f0",
|
|
36
|
+
borderRadius: 100,
|
|
37
|
+
height: 6,
|
|
38
|
+
marginVertical: 5,
|
|
39
|
+
width: 45,
|
|
40
|
+
},
|
|
41
|
+
parentContainer: {
|
|
42
|
+
alignItems: "center",
|
|
43
|
+
height: "100%",
|
|
44
|
+
justifyContent: "center",
|
|
45
|
+
width: "100%",
|
|
46
|
+
},
|
|
47
|
+
safearea: {
|
|
48
|
+
left: 999999,
|
|
49
|
+
position: "absolute",
|
|
50
|
+
top: 999999,
|
|
51
|
+
},
|
|
52
|
+
scrollView: {
|
|
53
|
+
backgroundColor: "transparent",
|
|
54
|
+
height: "100%",
|
|
55
|
+
width: "100%",
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
export function getDeviceHeight(statusBarTranslucent: boolean | undefined): number {
|
|
60
|
+
const height = Dimensions.get("window").height;
|
|
61
|
+
|
|
62
|
+
if (Platform.OS === "android" && !statusBarTranslucent) {
|
|
63
|
+
return StatusBar.currentHeight ? height - StatusBar.currentHeight : height;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return height;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export const getElevation = (elevation?: number) => {
|
|
70
|
+
if (!elevation) {
|
|
71
|
+
return {};
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
boxShadow: `${0.3 * elevation}px ${0.5 * elevation}px ${0.7 * elevation}px rgba(0, 0, 0, 0.2)`,
|
|
75
|
+
elevation,
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export const SUPPORTED_ORIENTATIONS: (
|
|
80
|
+
| "portrait"
|
|
81
|
+
| "portrait-upside-down"
|
|
82
|
+
| "landscape"
|
|
83
|
+
| "landscape-left"
|
|
84
|
+
| "landscape-right"
|
|
85
|
+
)[] = ["portrait", "portrait-upside-down", "landscape", "landscape-left", "landscape-right"];
|
|
86
|
+
|
|
87
|
+
export const waitAsync = (ms: number): Promise<null> =>
|
|
88
|
+
new Promise((resolve) => {
|
|
89
|
+
setTimeout(() => {
|
|
90
|
+
resolve(null);
|
|
91
|
+
}, ms);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
const safeAreaInnerHeight = 0;
|
|
95
|
+
const dummyData = ["dummy"];
|
|
96
|
+
let safeAreaPaddingTop = Platform.OS === "android" ? StatusBar.currentHeight || 0 : 0;
|
|
97
|
+
let calculatedDeviceHeight = Dimensions.get("window").height;
|
|
98
|
+
|
|
99
|
+
type State = {
|
|
100
|
+
modalVisible: boolean;
|
|
101
|
+
scrollable: boolean;
|
|
102
|
+
layoutHasCalled: boolean;
|
|
103
|
+
keyboard: boolean;
|
|
104
|
+
deviceHeight: number;
|
|
105
|
+
deviceWidth: number;
|
|
106
|
+
portrait: boolean;
|
|
107
|
+
safeAreaInnerHeight: number;
|
|
108
|
+
paddingTop: number;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const defaultProps = {
|
|
112
|
+
animated: true,
|
|
113
|
+
bottomOffset: 0,
|
|
114
|
+
bounciness: 8,
|
|
115
|
+
closable: true,
|
|
116
|
+
closeAnimationDuration: 300,
|
|
117
|
+
closeOnPressBack: true,
|
|
118
|
+
closeOnTouchBackdrop: true,
|
|
119
|
+
defaultOverlayOpacity: 0.3,
|
|
120
|
+
delayActionSheetDrawTime: 0,
|
|
121
|
+
drawUnderStatusBar: true,
|
|
122
|
+
elevation: 5,
|
|
123
|
+
extraScroll: 0,
|
|
124
|
+
gestureEnabled: false,
|
|
125
|
+
indicatorColor: "#f0f0f0",
|
|
126
|
+
initialOffsetFromBottom: 1,
|
|
127
|
+
keyboardMode: "padding",
|
|
128
|
+
openAnimationSpeed: 12,
|
|
129
|
+
overlayColor: "black",
|
|
130
|
+
springOffset: 100,
|
|
131
|
+
statusBarTranslucent: true,
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
type Props = Partial<typeof defaultProps> & ActionSheetProps;
|
|
135
|
+
|
|
136
|
+
export class ActionSheet extends Component<Props, State, any> {
|
|
137
|
+
static defaultProps = defaultProps;
|
|
138
|
+
|
|
139
|
+
actionSheetHeight = 0;
|
|
140
|
+
|
|
141
|
+
keyboardDidShowListener: EmitterSubscription | null = null;
|
|
142
|
+
|
|
143
|
+
keyboardDidHideListener: EmitterSubscription | null = null;
|
|
144
|
+
|
|
145
|
+
prevScroll = 0;
|
|
146
|
+
|
|
147
|
+
timeout: any | null = null;
|
|
148
|
+
|
|
149
|
+
offsetY = 0;
|
|
150
|
+
|
|
151
|
+
currentOffsetFromBottom = 0;
|
|
152
|
+
|
|
153
|
+
scrollAnimationEndValue = 0;
|
|
154
|
+
|
|
155
|
+
hasBounced = false;
|
|
156
|
+
|
|
157
|
+
layoutHasCalled = false;
|
|
158
|
+
|
|
159
|
+
isClosing = false;
|
|
160
|
+
|
|
161
|
+
isRecoiling = false;
|
|
162
|
+
|
|
163
|
+
isReachedTop = false;
|
|
164
|
+
|
|
165
|
+
deviceLayoutCalled = false;
|
|
166
|
+
|
|
167
|
+
scrollViewRef: React.RefObject<any>;
|
|
168
|
+
|
|
169
|
+
safeAreaViewRef: React.RefObject<any>;
|
|
170
|
+
|
|
171
|
+
transformValue: Animated.Value;
|
|
172
|
+
|
|
173
|
+
opacityValue: Animated.Value;
|
|
174
|
+
|
|
175
|
+
borderRadius: Animated.Value;
|
|
176
|
+
|
|
177
|
+
underlayTranslateY: Animated.Value;
|
|
178
|
+
|
|
179
|
+
underlayScale: Animated.Value;
|
|
180
|
+
|
|
181
|
+
indicatorTranslateY: Animated.Value;
|
|
182
|
+
|
|
183
|
+
constructor(props: ActionSheetProps) {
|
|
184
|
+
super(props);
|
|
185
|
+
this.state = {
|
|
186
|
+
deviceHeight: calculatedDeviceHeight || getDeviceHeight(this.props.statusBarTranslucent),
|
|
187
|
+
deviceWidth: Dimensions.get("window").width,
|
|
188
|
+
keyboard: false,
|
|
189
|
+
layoutHasCalled: false,
|
|
190
|
+
modalVisible: false,
|
|
191
|
+
paddingTop: safeAreaPaddingTop,
|
|
192
|
+
portrait: true,
|
|
193
|
+
safeAreaInnerHeight,
|
|
194
|
+
scrollable: false,
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
this.actionSheetHeight = 0;
|
|
198
|
+
this.prevScroll = 0;
|
|
199
|
+
this.scrollAnimationEndValue = 0;
|
|
200
|
+
this.hasBounced = false;
|
|
201
|
+
this.scrollViewRef = createRef();
|
|
202
|
+
this.layoutHasCalled = false;
|
|
203
|
+
this.isClosing = false;
|
|
204
|
+
this.isRecoiling = false;
|
|
205
|
+
this.offsetY = 0;
|
|
206
|
+
this.safeAreaViewRef = createRef();
|
|
207
|
+
this.transformValue = new Animated.Value(0);
|
|
208
|
+
this.opacityValue = new Animated.Value(0);
|
|
209
|
+
this.borderRadius = new Animated.Value(10);
|
|
210
|
+
this.currentOffsetFromBottom = this.props.initialOffsetFromBottom as number;
|
|
211
|
+
this.underlayTranslateY = new Animated.Value(100);
|
|
212
|
+
this.underlayScale = new Animated.Value(1);
|
|
213
|
+
this.indicatorTranslateY = new Animated.Value(-this.state.paddingTop | 0);
|
|
214
|
+
this.isReachedTop = false;
|
|
215
|
+
this.deviceLayoutCalled = false;
|
|
216
|
+
this.timeout = null;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Snap ActionSheet to Offset
|
|
221
|
+
*/
|
|
222
|
+
|
|
223
|
+
snapToOffset = (offset: number) => {
|
|
224
|
+
const correction = this.state.deviceHeight * 0.15;
|
|
225
|
+
const extraScroll = this.props.extraScroll || 0;
|
|
226
|
+
const scrollOffset = this.props.gestureEnabled
|
|
227
|
+
? offset + correction + extraScroll
|
|
228
|
+
: offset + correction + extraScroll;
|
|
229
|
+
this.currentOffsetFromBottom = offset / this.actionSheetHeight;
|
|
230
|
+
this._scrollTo(scrollOffset);
|
|
231
|
+
this.updateActionSheetPosition(scrollOffset);
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
// Open the ActionSheet
|
|
235
|
+
show = () => {
|
|
236
|
+
this.setModalVisible(true);
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
// Close the ActionSheet
|
|
240
|
+
hide = () => {
|
|
241
|
+
this.setModalVisible(false);
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Open/Close the ActionSheet
|
|
246
|
+
*/
|
|
247
|
+
setModalVisible = (visible: boolean) => {
|
|
248
|
+
let modalVisible = this.state.modalVisible;
|
|
249
|
+
if (visible !== undefined) {
|
|
250
|
+
if (modalVisible === visible) {
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
modalVisible = !visible;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (!modalVisible) {
|
|
257
|
+
this.setState({
|
|
258
|
+
modalVisible: true,
|
|
259
|
+
scrollable: this.props.gestureEnabled || false,
|
|
260
|
+
});
|
|
261
|
+
} else {
|
|
262
|
+
this._hideModal();
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
_hideAnimation() {
|
|
267
|
+
const {
|
|
268
|
+
animated,
|
|
269
|
+
closeAnimationDuration,
|
|
270
|
+
bottomOffset,
|
|
271
|
+
initialOffsetFromBottom,
|
|
272
|
+
extraScroll,
|
|
273
|
+
closable,
|
|
274
|
+
} = this.props;
|
|
275
|
+
|
|
276
|
+
Animated.parallel([
|
|
277
|
+
Animated.timing(this.opacityValue, {
|
|
278
|
+
duration: animated ? closeAnimationDuration : 1,
|
|
279
|
+
toValue: closable ? 0 : 1,
|
|
280
|
+
useNativeDriver: true,
|
|
281
|
+
}),
|
|
282
|
+
Animated.timing(this.transformValue, {
|
|
283
|
+
duration: animated ? closeAnimationDuration : 1,
|
|
284
|
+
toValue: closable ? this.actionSheetHeight * 2 : 0,
|
|
285
|
+
useNativeDriver: true,
|
|
286
|
+
}),
|
|
287
|
+
]).start();
|
|
288
|
+
|
|
289
|
+
void waitAsync((closeAnimationDuration as number) / 1.5).then(() => {
|
|
290
|
+
if (!closable) {
|
|
291
|
+
if (bottomOffset && bottomOffset > 0) {
|
|
292
|
+
this.snapToOffset(bottomOffset);
|
|
293
|
+
} else {
|
|
294
|
+
this._scrollTo(
|
|
295
|
+
((this.actionSheetHeight * (initialOffsetFromBottom || 0)) as number) +
|
|
296
|
+
this.state.deviceHeight * 0.1 +
|
|
297
|
+
(extraScroll ?? 0),
|
|
298
|
+
true
|
|
299
|
+
);
|
|
300
|
+
this.currentOffsetFromBottom = initialOffsetFromBottom as number;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
this.isClosing = false;
|
|
304
|
+
} else {
|
|
305
|
+
this._scrollTo(0, false);
|
|
306
|
+
this.currentOffsetFromBottom = initialOffsetFromBottom as number;
|
|
307
|
+
this.setState(
|
|
308
|
+
{
|
|
309
|
+
modalVisible: !closable,
|
|
310
|
+
},
|
|
311
|
+
() => {
|
|
312
|
+
this.isClosing = false;
|
|
313
|
+
this.isReachedTop = false;
|
|
314
|
+
this.props.onPositionChanged?.(false);
|
|
315
|
+
this.indicatorTranslateY.setValue(-this.state.paddingTop);
|
|
316
|
+
this.layoutHasCalled = false;
|
|
317
|
+
this.deviceLayoutCalled = false;
|
|
318
|
+
this.props.onClose?.();
|
|
319
|
+
}
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
_hideModal = () => {
|
|
326
|
+
if (this.isClosing) return;
|
|
327
|
+
this.isClosing = true;
|
|
328
|
+
this._hideAnimation();
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
measure = async (): Promise<number> => {
|
|
332
|
+
return new Promise((resolve) => {
|
|
333
|
+
setTimeout(() => {
|
|
334
|
+
UIManager.measureInWindow(
|
|
335
|
+
this.safeAreaViewRef.current._nativeTag,
|
|
336
|
+
(_x, _y, _width, height) => {
|
|
337
|
+
safeAreaPaddingTop = height;
|
|
338
|
+
resolve(height === 0 ? 20 : height);
|
|
339
|
+
}
|
|
340
|
+
);
|
|
341
|
+
}, 100);
|
|
342
|
+
});
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
_showModal = async (event: LayoutChangeEvent) => {
|
|
346
|
+
const {gestureEnabled, delayActionSheetDraw, delayActionSheetDrawTime} = this.props;
|
|
347
|
+
|
|
348
|
+
if (!event?.nativeEvent) return;
|
|
349
|
+
const height = event.nativeEvent.layout.height;
|
|
350
|
+
if (this.layoutHasCalled) {
|
|
351
|
+
this.actionSheetHeight = height;
|
|
352
|
+
this._returnToPrevScrollPosition(height);
|
|
353
|
+
return;
|
|
354
|
+
} else {
|
|
355
|
+
this.layoutHasCalled = true;
|
|
356
|
+
this.actionSheetHeight = height;
|
|
357
|
+
const scrollOffset = this.getInitialScrollPosition();
|
|
358
|
+
this.isRecoiling = false;
|
|
359
|
+
if (Platform.OS === "ios") {
|
|
360
|
+
await waitAsync(delayActionSheetDrawTime as number);
|
|
361
|
+
} else {
|
|
362
|
+
if (delayActionSheetDraw) {
|
|
363
|
+
await waitAsync(delayActionSheetDrawTime as number);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
this._scrollTo(scrollOffset, false);
|
|
367
|
+
this.prevScroll = scrollOffset;
|
|
368
|
+
if (Platform.OS === "ios") {
|
|
369
|
+
await waitAsync(delayActionSheetDrawTime ?? 0 / 2);
|
|
370
|
+
} else {
|
|
371
|
+
if (delayActionSheetDraw) {
|
|
372
|
+
await waitAsync(delayActionSheetDrawTime ?? 0 / 2);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
this._openAnimation(scrollOffset);
|
|
376
|
+
this.underlayScale.setValue(1);
|
|
377
|
+
this.underlayTranslateY.setValue(100);
|
|
378
|
+
if (!gestureEnabled) {
|
|
379
|
+
this.props.onPositionChanged?.(true);
|
|
380
|
+
}
|
|
381
|
+
this.updateActionSheetPosition(scrollOffset);
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
_openAnimation = (scrollOffset: number) => {
|
|
386
|
+
const {bounciness, bounceOnOpen, animated, openAnimationSpeed} = this.props;
|
|
387
|
+
|
|
388
|
+
if (animated) {
|
|
389
|
+
this.transformValue.setValue(scrollOffset);
|
|
390
|
+
Animated.parallel([
|
|
391
|
+
Animated.spring(this.transformValue, {
|
|
392
|
+
bounciness: bounceOnOpen ? bounciness : 1,
|
|
393
|
+
speed: openAnimationSpeed,
|
|
394
|
+
toValue: 0,
|
|
395
|
+
useNativeDriver: true,
|
|
396
|
+
}),
|
|
397
|
+
Animated.timing(this.opacityValue, {
|
|
398
|
+
duration: 150,
|
|
399
|
+
toValue: 1,
|
|
400
|
+
useNativeDriver: true,
|
|
401
|
+
}),
|
|
402
|
+
]).start();
|
|
403
|
+
} else {
|
|
404
|
+
this.opacityValue.setValue(1);
|
|
405
|
+
}
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
_onScrollBegin = async () => {};
|
|
409
|
+
|
|
410
|
+
_onScrollBeginDrag = async (event: NativeSyntheticEvent<NativeScrollEvent>) => {
|
|
411
|
+
this.prevScroll = event.nativeEvent.contentOffset.y;
|
|
412
|
+
};
|
|
413
|
+
|
|
414
|
+
_applyHeightLimiter() {
|
|
415
|
+
if (this.actionSheetHeight > this.state.deviceHeight) {
|
|
416
|
+
this.actionSheetHeight =
|
|
417
|
+
this.actionSheetHeight - (this.actionSheetHeight - this.state.deviceHeight);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
_onScrollEnd = async (event: NativeSyntheticEvent<NativeScrollEvent>) => {
|
|
422
|
+
const {springOffset, extraScroll} = this.props;
|
|
423
|
+
const verticalOffset = event.nativeEvent.contentOffset.y;
|
|
424
|
+
|
|
425
|
+
const correction = this.state.deviceHeight * 0.15;
|
|
426
|
+
if (this.isRecoiling) return;
|
|
427
|
+
|
|
428
|
+
if (this.prevScroll < verticalOffset) {
|
|
429
|
+
if (verticalOffset - this.prevScroll > (springOffset ?? 0) * 0.75) {
|
|
430
|
+
this.isRecoiling = true;
|
|
431
|
+
|
|
432
|
+
this._applyHeightLimiter();
|
|
433
|
+
this.currentOffsetFromBottom =
|
|
434
|
+
this.currentOffsetFromBottom < (this.props.initialOffsetFromBottom ?? 0)
|
|
435
|
+
? (this.props.initialOffsetFromBottom as number)
|
|
436
|
+
: 1;
|
|
437
|
+
const scrollOffset =
|
|
438
|
+
this.actionSheetHeight * this.currentOffsetFromBottom + correction + (extraScroll ?? 0);
|
|
439
|
+
|
|
440
|
+
this._scrollTo(scrollOffset);
|
|
441
|
+
await waitAsync(300);
|
|
442
|
+
this.isRecoiling = false;
|
|
443
|
+
this.props.onPositionChanged?.(true);
|
|
444
|
+
} else {
|
|
445
|
+
this._returnToPrevScrollPosition(this.actionSheetHeight);
|
|
446
|
+
}
|
|
447
|
+
} else {
|
|
448
|
+
if (this.prevScroll - verticalOffset > (springOffset ?? 0)) {
|
|
449
|
+
this._hideModal();
|
|
450
|
+
} else {
|
|
451
|
+
if (this.isRecoiling) {
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
this.isRecoiling = true;
|
|
456
|
+
this._returnToPrevScrollPosition(this.actionSheetHeight);
|
|
457
|
+
await waitAsync(300);
|
|
458
|
+
this.isRecoiling = false;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
};
|
|
462
|
+
|
|
463
|
+
updateActionSheetPosition(scrollPosition: number) {
|
|
464
|
+
if (this.actionSheetHeight >= this.state.deviceHeight - 1) {
|
|
465
|
+
const correction = this.state.deviceHeight * 0.15;
|
|
466
|
+
const distanceFromTop = this.actionSheetHeight + correction - scrollPosition;
|
|
467
|
+
if (distanceFromTop < safeAreaPaddingTop) {
|
|
468
|
+
if (!this.props.drawUnderStatusBar) return;
|
|
469
|
+
this.indicatorTranslateY.setValue(0);
|
|
470
|
+
} else {
|
|
471
|
+
this.indicatorTranslateY.setValue(-safeAreaPaddingTop);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
_returnToPrevScrollPosition(height: number) {
|
|
477
|
+
const correction = this.state.deviceHeight * 0.15;
|
|
478
|
+
const scrollOffset =
|
|
479
|
+
height * this.currentOffsetFromBottom + correction + (this.props.extraScroll ?? 0);
|
|
480
|
+
|
|
481
|
+
this.updateActionSheetPosition(scrollOffset);
|
|
482
|
+
this._scrollTo(scrollOffset);
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
_scrollTo = (y: number, animated = true) => {
|
|
486
|
+
this.scrollAnimationEndValue = y;
|
|
487
|
+
this.prevScroll = y;
|
|
488
|
+
this.scrollViewRef.current?._listRef._scrollRef.scrollTo({
|
|
489
|
+
animated,
|
|
490
|
+
x: 0,
|
|
491
|
+
y: this.scrollAnimationEndValue,
|
|
492
|
+
});
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
_onTouchMove = () => {
|
|
496
|
+
if (this.props.closeOnTouchBackdrop) {
|
|
497
|
+
this._hideModal();
|
|
498
|
+
}
|
|
499
|
+
this.setState({
|
|
500
|
+
scrollable: false,
|
|
501
|
+
});
|
|
502
|
+
};
|
|
503
|
+
|
|
504
|
+
_onTouchStart = () => {
|
|
505
|
+
if (this.props.closeOnTouchBackdrop) {
|
|
506
|
+
this._hideModal();
|
|
507
|
+
}
|
|
508
|
+
this.setState({
|
|
509
|
+
scrollable: false,
|
|
510
|
+
});
|
|
511
|
+
};
|
|
512
|
+
|
|
513
|
+
_onTouchEnd = () => {
|
|
514
|
+
this._returnToPrevScrollPosition(this.actionSheetHeight);
|
|
515
|
+
if (this.props.gestureEnabled) {
|
|
516
|
+
this.setState({
|
|
517
|
+
scrollable: true,
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
};
|
|
521
|
+
|
|
522
|
+
_onScroll = (event: NativeSyntheticEvent<NativeScrollEvent>) => {
|
|
523
|
+
this.offsetY = event.nativeEvent.contentOffset.y;
|
|
524
|
+
|
|
525
|
+
const correction = this.state.deviceHeight * 0.15;
|
|
526
|
+
const distanceFromTop = this.actionSheetHeight + correction - this.offsetY;
|
|
527
|
+
|
|
528
|
+
if (this.actionSheetHeight < this.offsetY) {
|
|
529
|
+
if (!this.isReachedTop) {
|
|
530
|
+
this.isReachedTop = true;
|
|
531
|
+
this.props.onPositionChanged?.(true);
|
|
532
|
+
}
|
|
533
|
+
} else {
|
|
534
|
+
if (this.isReachedTop) {
|
|
535
|
+
this.isReachedTop = false;
|
|
536
|
+
this.props.onPositionChanged?.(false);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
if (this.actionSheetHeight >= this.state.deviceHeight - 1) {
|
|
541
|
+
if (distanceFromTop < safeAreaPaddingTop) {
|
|
542
|
+
if (!this.props.drawUnderStatusBar) return;
|
|
543
|
+
|
|
544
|
+
this.indicatorTranslateY.setValue(
|
|
545
|
+
-this.state.paddingTop + (safeAreaPaddingTop - distanceFromTop)
|
|
546
|
+
);
|
|
547
|
+
} else {
|
|
548
|
+
this.indicatorTranslateY.setValue(-safeAreaPaddingTop);
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
};
|
|
552
|
+
|
|
553
|
+
_onRequestClose = () => {
|
|
554
|
+
if (this.props.closeOnPressBack) this._hideModal();
|
|
555
|
+
};
|
|
556
|
+
|
|
557
|
+
_onTouchBackdrop = () => {
|
|
558
|
+
if (this.props.closeOnTouchBackdrop) {
|
|
559
|
+
this._hideModal();
|
|
560
|
+
}
|
|
561
|
+
};
|
|
562
|
+
|
|
563
|
+
componentDidMount() {
|
|
564
|
+
this.keyboardDidShowListener = Keyboard.addListener(
|
|
565
|
+
Platform.OS === "android" ? "keyboardDidShow" : "keyboardWillShow",
|
|
566
|
+
this._onKeyboardShow
|
|
567
|
+
);
|
|
568
|
+
|
|
569
|
+
this.keyboardDidHideListener = Keyboard.addListener(
|
|
570
|
+
Platform.OS === "android" ? "keyboardDidHide" : "keyboardWillHide",
|
|
571
|
+
this._onKeyboardHide
|
|
572
|
+
);
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
_onKeyboardShow = (event: KeyboardEvent) => {
|
|
576
|
+
this.setState({
|
|
577
|
+
keyboard: true,
|
|
578
|
+
});
|
|
579
|
+
const ReactNativeVersion = require("react-native/Libraries/Core/ReactNativeVersion");
|
|
580
|
+
|
|
581
|
+
let v = ReactNativeVersion.version.major + ReactNativeVersion.version.minor;
|
|
582
|
+
v = parseInt(v, 10);
|
|
583
|
+
|
|
584
|
+
if (v >= 63 || Platform.OS === "ios") {
|
|
585
|
+
const keyboardHeight = event.endCoordinates.height;
|
|
586
|
+
const {height: windowHeight} = Dimensions.get("window");
|
|
587
|
+
|
|
588
|
+
const currentlyFocusedField = TextInput.State.currentlyFocusedField
|
|
589
|
+
? findNodeHandle(TextInput.State.currentlyFocusedField())
|
|
590
|
+
: TextInput.State.currentlyFocusedField();
|
|
591
|
+
|
|
592
|
+
if (!currentlyFocusedField) {
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
UIManager.measure(
|
|
597
|
+
currentlyFocusedField,
|
|
598
|
+
(_originX, _originY, _width, height, _pageX, pageY) => {
|
|
599
|
+
const fieldHeight = height;
|
|
600
|
+
const gap = windowHeight - keyboardHeight - (pageY + fieldHeight);
|
|
601
|
+
if (gap >= 0) {
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
604
|
+
const toValue =
|
|
605
|
+
this.props.keyboardMode === "position" ? -(keyboardHeight + 15) : gap - 10;
|
|
606
|
+
|
|
607
|
+
Animated.timing(this.transformValue, {
|
|
608
|
+
duration: 250,
|
|
609
|
+
toValue,
|
|
610
|
+
useNativeDriver: true,
|
|
611
|
+
}).start();
|
|
612
|
+
}
|
|
613
|
+
);
|
|
614
|
+
} else {
|
|
615
|
+
Animated.timing(this.transformValue, {
|
|
616
|
+
duration: 250,
|
|
617
|
+
toValue: -10,
|
|
618
|
+
useNativeDriver: true,
|
|
619
|
+
}).start();
|
|
620
|
+
}
|
|
621
|
+
};
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* Attach this to any child ScrollView Component's onScrollEndDrag,
|
|
625
|
+
* onMomentumScrollEnd,onScrollAnimationEnd callbacks to handle the ActionSheet
|
|
626
|
+
* closing and bouncing back properly.
|
|
627
|
+
*/
|
|
628
|
+
|
|
629
|
+
handleChildScrollEnd = async () => {
|
|
630
|
+
if (this.offsetY > this.prevScroll) return;
|
|
631
|
+
if (this.prevScroll - (this.props.springOffset ?? 0) > this.offsetY) {
|
|
632
|
+
const scrollOffset = this.getInitialScrollPosition();
|
|
633
|
+
if (this.offsetY > scrollOffset - 100) {
|
|
634
|
+
this.isRecoiling = true;
|
|
635
|
+
this._scrollTo(scrollOffset);
|
|
636
|
+
this.currentOffsetFromBottom = this.props.initialOffsetFromBottom ?? 0;
|
|
637
|
+
this.prevScroll = scrollOffset;
|
|
638
|
+
setTimeout(() => {
|
|
639
|
+
this.isRecoiling = false;
|
|
640
|
+
}, 500);
|
|
641
|
+
} else {
|
|
642
|
+
this._hideModal();
|
|
643
|
+
}
|
|
644
|
+
} else {
|
|
645
|
+
this.isRecoiling = true;
|
|
646
|
+
this._scrollTo(this.prevScroll, true);
|
|
647
|
+
setTimeout(() => {
|
|
648
|
+
this.isRecoiling = false;
|
|
649
|
+
}, 500);
|
|
650
|
+
}
|
|
651
|
+
};
|
|
652
|
+
|
|
653
|
+
_onKeyboardHide = () => {
|
|
654
|
+
this.setState({
|
|
655
|
+
keyboard: false,
|
|
656
|
+
});
|
|
657
|
+
this.opacityValue.setValue(1);
|
|
658
|
+
Animated.timing(this.transformValue, {
|
|
659
|
+
duration: 100,
|
|
660
|
+
toValue: 0,
|
|
661
|
+
useNativeDriver: true,
|
|
662
|
+
}).start();
|
|
663
|
+
};
|
|
664
|
+
|
|
665
|
+
componentWillUnmount() {
|
|
666
|
+
this.keyboardDidShowListener?.remove();
|
|
667
|
+
this.keyboardDidHideListener?.remove();
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
_onDeviceLayout = async (_event: any) => {
|
|
671
|
+
const event = {..._event};
|
|
672
|
+
|
|
673
|
+
if (this.timeout) {
|
|
674
|
+
clearTimeout(this.timeout);
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
this.timeout = setTimeout(async () => {
|
|
678
|
+
let safeMarginFromTop = 0;
|
|
679
|
+
const measuredPadding =
|
|
680
|
+
Platform.OS === "ios" ? await this.measure() : StatusBar.currentHeight;
|
|
681
|
+
|
|
682
|
+
if (!this.props.drawUnderStatusBar) {
|
|
683
|
+
if (Platform.OS === "android" && !this.props.statusBarTranslucent) return;
|
|
684
|
+
safeMarginFromTop = measuredPadding ?? 0;
|
|
685
|
+
this.indicatorTranslateY.setValue(-(measuredPadding as number));
|
|
686
|
+
} else {
|
|
687
|
+
this.updateActionSheetPosition(this.offsetY);
|
|
688
|
+
}
|
|
689
|
+
const height = event.nativeEvent.layout.height - safeMarginFromTop;
|
|
690
|
+
const width = Dimensions.get("window").width;
|
|
691
|
+
if (
|
|
692
|
+
height?.toFixed(0) === calculatedDeviceHeight?.toFixed(0) &&
|
|
693
|
+
width?.toFixed(0) === this.state.deviceWidth?.toFixed(0) &&
|
|
694
|
+
this.deviceLayoutCalled
|
|
695
|
+
)
|
|
696
|
+
return;
|
|
697
|
+
this.deviceLayoutCalled = true;
|
|
698
|
+
calculatedDeviceHeight = height;
|
|
699
|
+
this.setState({
|
|
700
|
+
deviceHeight: height,
|
|
701
|
+
deviceWidth: width,
|
|
702
|
+
paddingTop: measuredPadding ?? 0,
|
|
703
|
+
portrait: height > width,
|
|
704
|
+
});
|
|
705
|
+
}, 1);
|
|
706
|
+
};
|
|
707
|
+
|
|
708
|
+
getInitialScrollPosition() {
|
|
709
|
+
this._applyHeightLimiter();
|
|
710
|
+
const correction = this.state.deviceHeight * 0.15;
|
|
711
|
+
const scrollPosition = this.props.gestureEnabled
|
|
712
|
+
? this.actionSheetHeight * (this.props.initialOffsetFromBottom ?? 0) +
|
|
713
|
+
correction +
|
|
714
|
+
(this.props.extraScroll ?? 0)
|
|
715
|
+
: this.actionSheetHeight + correction + (this.props.extraScroll ?? 0);
|
|
716
|
+
this.currentOffsetFromBottom = this.props.initialOffsetFromBottom ?? 0;
|
|
717
|
+
this.updateActionSheetPosition(scrollPosition);
|
|
718
|
+
|
|
719
|
+
return scrollPosition;
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
_keyExtractor = (item: any) => item;
|
|
723
|
+
|
|
724
|
+
render() {
|
|
725
|
+
const {scrollable, modalVisible, keyboard} = this.state;
|
|
726
|
+
const {
|
|
727
|
+
onOpen,
|
|
728
|
+
overlayColor,
|
|
729
|
+
gestureEnabled,
|
|
730
|
+
elevation,
|
|
731
|
+
indicatorColor,
|
|
732
|
+
defaultOverlayOpacity,
|
|
733
|
+
children,
|
|
734
|
+
containerStyle,
|
|
735
|
+
CustomHeaderComponent,
|
|
736
|
+
headerAlwaysVisible,
|
|
737
|
+
keyboardShouldPersistTaps,
|
|
738
|
+
statusBarTranslucent,
|
|
739
|
+
} = this.props;
|
|
740
|
+
|
|
741
|
+
return (
|
|
742
|
+
<Modal
|
|
743
|
+
animationType="none"
|
|
744
|
+
onRequestClose={this._onRequestClose}
|
|
745
|
+
// testID={testID}
|
|
746
|
+
onShow={onOpen}
|
|
747
|
+
statusBarTranslucent={statusBarTranslucent}
|
|
748
|
+
supportedOrientations={SUPPORTED_ORIENTATIONS}
|
|
749
|
+
transparent
|
|
750
|
+
visible={modalVisible}
|
|
751
|
+
>
|
|
752
|
+
<Animated.View
|
|
753
|
+
onLayout={this._onDeviceLayout}
|
|
754
|
+
style={[
|
|
755
|
+
styles.parentContainer,
|
|
756
|
+
{
|
|
757
|
+
opacity: this.opacityValue,
|
|
758
|
+
width: this.state.deviceWidth,
|
|
759
|
+
},
|
|
760
|
+
]}
|
|
761
|
+
>
|
|
762
|
+
<SafeAreaView ref={this.safeAreaViewRef} style={styles.safearea}>
|
|
763
|
+
<View />
|
|
764
|
+
</SafeAreaView>
|
|
765
|
+
<FlatList
|
|
766
|
+
bounces={false}
|
|
767
|
+
contentContainerStyle={{
|
|
768
|
+
width: this.state.deviceWidth,
|
|
769
|
+
}}
|
|
770
|
+
data={dummyData}
|
|
771
|
+
keyboardShouldPersistTaps={keyboardShouldPersistTaps}
|
|
772
|
+
keyExtractor={this._keyExtractor}
|
|
773
|
+
onMomentumScrollBegin={this._onScrollBegin}
|
|
774
|
+
onMomentumScrollEnd={this._onScrollEnd}
|
|
775
|
+
onScroll={this._onScroll}
|
|
776
|
+
onScrollBeginDrag={this._onScrollBeginDrag}
|
|
777
|
+
onTouchEnd={this._onTouchEnd}
|
|
778
|
+
ref={this.scrollViewRef}
|
|
779
|
+
renderItem={() => (
|
|
780
|
+
<View
|
|
781
|
+
style={{
|
|
782
|
+
width: "100%",
|
|
783
|
+
}}
|
|
784
|
+
>
|
|
785
|
+
<Animated.View
|
|
786
|
+
onTouchEnd={this._onTouchBackdrop}
|
|
787
|
+
onTouchMove={this._onTouchBackdrop}
|
|
788
|
+
onTouchStart={this._onTouchBackdrop}
|
|
789
|
+
style={{
|
|
790
|
+
backgroundColor: overlayColor,
|
|
791
|
+
height: "100%",
|
|
792
|
+
opacity: defaultOverlayOpacity,
|
|
793
|
+
position: "absolute",
|
|
794
|
+
width: "100%",
|
|
795
|
+
zIndex: 1,
|
|
796
|
+
}}
|
|
797
|
+
/>
|
|
798
|
+
<View
|
|
799
|
+
onTouchEnd={this._onTouchEnd}
|
|
800
|
+
onTouchMove={this._onTouchMove}
|
|
801
|
+
onTouchStart={this._onTouchStart}
|
|
802
|
+
style={{
|
|
803
|
+
height: this.state.deviceHeight * 1.15,
|
|
804
|
+
width: "100%",
|
|
805
|
+
zIndex: 10,
|
|
806
|
+
}}
|
|
807
|
+
>
|
|
808
|
+
<Pressable
|
|
809
|
+
aria-role="button"
|
|
810
|
+
onLongPress={this._onTouchBackdrop}
|
|
811
|
+
onPress={this._onTouchBackdrop}
|
|
812
|
+
style={{
|
|
813
|
+
height: this.state.deviceHeight * 1.15,
|
|
814
|
+
width: "100%",
|
|
815
|
+
}}
|
|
816
|
+
/>
|
|
817
|
+
</View>
|
|
818
|
+
|
|
819
|
+
<Animated.View
|
|
820
|
+
onLayout={this._showModal}
|
|
821
|
+
style={[
|
|
822
|
+
styles.container,
|
|
823
|
+
{
|
|
824
|
+
borderRadius: 10,
|
|
825
|
+
},
|
|
826
|
+
containerStyle,
|
|
827
|
+
{
|
|
828
|
+
...getElevation(elevation),
|
|
829
|
+
maxHeight: this.state.deviceHeight,
|
|
830
|
+
opacity: this.opacityValue,
|
|
831
|
+
transform: [
|
|
832
|
+
{
|
|
833
|
+
translateY: this.transformValue,
|
|
834
|
+
},
|
|
835
|
+
],
|
|
836
|
+
zIndex: 11,
|
|
837
|
+
},
|
|
838
|
+
]}
|
|
839
|
+
>
|
|
840
|
+
<Animated.View
|
|
841
|
+
style={{
|
|
842
|
+
marginTop: this.state.paddingTop,
|
|
843
|
+
maxHeight: this.state.deviceHeight,
|
|
844
|
+
transform: [
|
|
845
|
+
{
|
|
846
|
+
translateY: this.indicatorTranslateY,
|
|
847
|
+
},
|
|
848
|
+
],
|
|
849
|
+
}}
|
|
850
|
+
>
|
|
851
|
+
{gestureEnabled || headerAlwaysVisible ? (
|
|
852
|
+
CustomHeaderComponent ? (
|
|
853
|
+
CustomHeaderComponent
|
|
854
|
+
) : (
|
|
855
|
+
<Animated.View
|
|
856
|
+
style={[styles.indicator, {backgroundColor: indicatorColor}]}
|
|
857
|
+
/>
|
|
858
|
+
)
|
|
859
|
+
) : null}
|
|
860
|
+
|
|
861
|
+
{children}
|
|
862
|
+
</Animated.View>
|
|
863
|
+
</Animated.View>
|
|
864
|
+
</View>
|
|
865
|
+
)}
|
|
866
|
+
scrollEnabled={scrollable && !keyboard}
|
|
867
|
+
scrollEventThrottle={5}
|
|
868
|
+
scrollsToTop={false}
|
|
869
|
+
showsVerticalScrollIndicator={false}
|
|
870
|
+
style={[
|
|
871
|
+
styles.scrollView,
|
|
872
|
+
{
|
|
873
|
+
width: this.state.deviceWidth,
|
|
874
|
+
},
|
|
875
|
+
]}
|
|
876
|
+
/>
|
|
877
|
+
</Animated.View>
|
|
878
|
+
</Modal>
|
|
879
|
+
);
|
|
880
|
+
}
|
|
881
|
+
}
|