Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add offline search functionality for addresses #35045

Merged
merged 115 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from 91 commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
a3de03d
offline search functinality for addresses
cooldev900 Nov 23, 2023
dcb0939
eliminate lint error
cooldev900 Nov 24, 2023
ec559a9
Merge branch 'main' of https://github.com/cooldev900/App into issues/…
cooldev900 Nov 24, 2023
d1f00b6
eliminate extra spaces
cooldev900 Nov 24, 2023
f4b3233
eliminate lint error
cooldev900 Nov 24, 2023
3927555
resolve conflict
cooldev900 Nov 28, 2023
254abbd
resolve conflict
cooldev900 Nov 28, 2023
bffc960
Merge branch 'main' of https://github.com/cooldev900/App into issues/…
cooldev900 Nov 28, 2023
45bcc82
show hint in offline state
cooldev900 Nov 29, 2023
113eff3
Merge branch 'main' of https://github.com/cooldev900/App into issues/…
cooldev900 Nov 30, 2023
46200f8
restore hint and update isSearchedPlace funtion
cooldev900 Dec 1, 2023
f84f234
update function name and jsDoc
cooldev900 Dec 1, 2023
879ee6a
handle overflow
cooldev900 Dec 4, 2023
3d2c7ce
Merge branch 'main' of https://github.com/cooldev900/App into issues/…
cooldev900 Dec 4, 2023
09f670c
fix prettier error
cooldev900 Dec 4, 2023
21c204d
add space on the comment
cooldev900 Dec 4, 2023
5bf583e
restore the update by merge
cooldev900 Dec 4, 2023
ffbef6c
add document for place
cooldev900 Dec 4, 2023
1badfc0
add the document for geometry
cooldev900 Dec 4, 2023
529a57b
Merge branch 'main' of https://github.com/cooldev900/App into issues/…
cooldev900 Dec 6, 2023
4760494
fix overflow on ios
cooldev900 Dec 8, 2023
8e37883
Merge branch 'main' of https://github.com/cooldev900/App into issues/…
cooldev900 Dec 8, 2023
fd79182
merge main
cooldev900 Dec 8, 2023
13a07cd
upadte height and back ground color
cooldev900 Dec 8, 2023
fd5978b
calculate list view style
cooldev900 Dec 8, 2023
cec47a1
update style depending device
cooldev900 Dec 8, 2023
3d212a4
fix lint error
cooldev900 Dec 8, 2023
b1f668f
fix prettier error
cooldev900 Dec 8, 2023
0aa04aa
create native file for mobile
cooldev900 Dec 11, 2023
ad6ab06
create getListViewHeight function
cooldev900 Dec 12, 2023
715d987
resolve conflict
cooldev900 Dec 13, 2023
e03748c
fix typo error
cooldev900 Dec 13, 2023
60e2285
resolve conflict
cooldev900 Dec 14, 2023
2f02fdd
fix lint
cooldev900 Dec 14, 2023
2421ec8
add const and fix bug
cooldev900 Dec 14, 2023
3d36e3e
remove lodash
cooldev900 Dec 14, 2023
af8fae1
Merge branch 'main' of https://github.com/cooldev900/App into issues/…
cooldev900 Dec 18, 2023
463d185
fix styles
cooldev900 Dec 18, 2023
232df83
Merge branch 'main' into issues/30123
cooldev900 Dec 19, 2023
3ee5a28
fix button movement error
cooldev900 Dec 19, 2023
01725ca
adjust form height on offline state
cooldev900 Dec 19, 2023
32882eb
update height in ios
cooldev900 Dec 20, 2023
1d2ba32
fix overflow styles
cooldev900 Dec 24, 2023
14d35c9
Merge branch 'main' of https://github.com/cooldev900/App into issues/…
cooldev900 Dec 24, 2023
8749419
reset focus state
cooldev900 Dec 24, 2023
3cff20c
use windowHeight instead of 100vh
cooldev900 Dec 24, 2023
4bd2ae6
updating styles for overflow
cooldev900 Dec 25, 2023
c135670
ios fix
cooldev900 Dec 26, 2023
aa9e2c5
fiix overflow issues in ios and safari
cooldev900 Dec 26, 2023
4e262bc
consider ios safari
cooldev900 Dec 26, 2023
93f48ae
eliminate shrinking list by save button
cooldev900 Jan 4, 2024
882d5c7
solve merge conflict
cooldev900 Jan 4, 2024
6fd9754
Merge branch 'main' of https://github.com/cooldev900/App into issues/…
cooldev900 Jan 4, 2024
86398c6
fix lint error
cooldev900 Jan 4, 2024
82e5ca0
keep responsivness in web
cooldev900 Jan 10, 2024
4e4fe79
resolve conflict
cooldev900 Jan 11, 2024
d6284d2
fix typo error
cooldev900 Jan 11, 2024
8837fe0
update explanation
cooldev900 Jan 12, 2024
7330834
Merge branch 'main' into issues/30123
pac-guerreiro Jan 23, 2024
76a7fda
fix(AddressSearch): addresses getting cropped
pac-guerreiro Jan 23, 2024
7a05d93
chore: cleanup unused code
pac-guerreiro Jan 24, 2024
2cf661c
chore: remove unused code
pac-guerreiro Jan 24, 2024
8f1e5a1
refactor: migrate files to typescript
pac-guerreiro Jan 24, 2024
1c5c0f7
Merge branch 'main' into issues/30123
pac-guerreiro Jan 30, 2024
87c3265
chore: revert changes
pac-guerreiro Jan 30, 2024
2740a6b
Merge branch 'main' into issues/30123
pac-guerreiro Feb 2, 2024
6337b57
chore: revert changes
pac-guerreiro Feb 2, 2024
3ecc869
refactor: apply pull request suggestion
pac-guerreiro Feb 2, 2024
af15403
fix: address search suggestions overflowing
pac-guerreiro Feb 7, 2024
d842db6
Merge branch 'main' into issues/30123
pac-guerreiro Feb 9, 2024
3be71e1
refactor: apply pull request suggestions
pac-guerreiro Feb 9, 2024
4dac414
Merge branch 'main' into issues/30123
pac-guerreiro Feb 13, 2024
3003023
Merge branch 'main' into issues/30123
pac-guerreiro Feb 15, 2024
8907eef
Merge branch 'main' into issues/30123
pac-guerreiro Feb 21, 2024
d4d9883
fix: submit button not fixed at the bottom of the screen on both andr…
pac-guerreiro Feb 22, 2024
557cf6d
Merge branch 'main' into issues/30123
pac-guerreiro Feb 22, 2024
08c9a5d
Merge branch 'main' into issues/30123
pac-guerreiro Feb 26, 2024
4da5ffe
fix: submit button positioning on address search
pac-guerreiro Feb 26, 2024
eda219c
Merge branch 'main' into issues/30123
pac-guerreiro Feb 29, 2024
b6b5741
Merge branch 'main' into issues/30123
pac-guerreiro Mar 11, 2024
a3dbfef
Merge branch 'main' into issues/30123
pac-guerreiro Mar 20, 2024
8c21175
fix: address suggestions list sizing
pac-guerreiro Mar 20, 2024
baf70a9
fix: submit button visibility on all platforms
pac-guerreiro Mar 22, 2024
0c38e44
Merge branch 'main' into issues/30123
pac-guerreiro Mar 22, 2024
7d58b3a
Merge branch 'main' into issues/30123
pac-guerreiro Mar 26, 2024
16b8027
refactor: apply pull request suggestions
pac-guerreiro Mar 27, 2024
c8dce42
Merge branch 'main' into issues/30123
pac-guerreiro Mar 28, 2024
3aef2b9
fix: submit button disappearing when web/desktop window is resized
pac-guerreiro Mar 28, 2024
580af72
refactor: apply pull request suggestions
pac-guerreiro Mar 28, 2024
97642c8
Merge branch 'main' into issues/30123
pac-guerreiro Apr 3, 2024
cb4eaeb
refactor: apply pull request suggestions
pac-guerreiro Apr 3, 2024
1693acd
Merge branch 'main' into issues/30123
pac-guerreiro Apr 5, 2024
9b74216
fix: wrong IOU distance request address error message when offline
pac-guerreiro Apr 5, 2024
a116369
fix: duplicate sizing name
pac-guerreiro Apr 5, 2024
553cd86
Merge branch 'main' into issues/30123
pac-guerreiro Apr 9, 2024
c2de6ef
refactor(prettier): code style
pac-guerreiro Apr 9, 2024
6fdb7a8
Merge branch 'main' into issues/30123
pac-guerreiro Apr 9, 2024
e34aaa2
Merge branch 'main' into issues/30123
pac-guerreiro Apr 9, 2024
32eb193
Merge branch 'main' into issues/30123
pac-guerreiro Apr 10, 2024
eb3175c
Merge branch 'main' into issues/30123
pac-guerreiro Apr 11, 2024
16f5d89
refactor: apply pull request suggestions
pac-guerreiro Apr 11, 2024
1097761
Merge branch 'main' into issues/30123
pac-guerreiro Apr 15, 2024
86905c4
Merge branch 'main' into issues/30123
pac-guerreiro Apr 16, 2024
18610b4
fix: address search titles missing on mobile
pac-guerreiro Apr 16, 2024
7446682
Merge branch 'main' into issues/30123
pac-guerreiro Apr 16, 2024
9f70527
Merge branch 'main' into issues/30123
pac-guerreiro Apr 17, 2024
ee38c7e
Merge branch 'main' into issues/30123
pac-guerreiro Apr 22, 2024
94dda99
Merge branch 'main' into issues/30123
pac-guerreiro Apr 29, 2024
3c2d677
refactor: revert change that prevents user from writing address in of…
pac-guerreiro Apr 29, 2024
3ce2ddf
Merge branch 'main' into issues/30123
pac-guerreiro May 15, 2024
0301900
refactor: split platform specific login into separate files
pac-guerreiro May 16, 2024
8468261
Merge branch 'main' into issues/30123
pac-guerreiro May 16, 2024
f7195c0
Merge branch 'main' into issues/30123
pac-guerreiro May 16, 2024
49e9755
fix: submit button overlapping form content
pac-guerreiro May 17, 2024
ae0ce2d
Merge branch 'main' into issues/30123
pac-guerreiro May 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const chatTypes = {
const cardActiveStates: number[] = [2, 3, 4, 7];

const CONST = {
RECENT_WAYPOINTS_NUMBER: 20,
MERGED_ACCOUNT_PREFIX: 'MERGED_',
DEFAULT_POLICY_ROOM_CHAT_TYPES: [chatTypes.POLICY_ADMINS, chatTypes.POLICY_ANNOUNCE, chatTypes.DOMAIN_ALL],

Expand Down
59 changes: 47 additions & 12 deletions src/components/AddressSearch/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,25 @@ import variables from '@styles/variables';
import CONST from '@src/CONST';
import CurrentLocationButton from './CurrentLocationButton';
import isCurrentTargetInsideContainer from './isCurrentTargetInsideContainer';
import type {AddressSearchProps, RenamedInputKeysProps} from './types';
import listViewOverflow from './listViewOverflow';
import type {AddressSearchProps, PredefinedPlace, RenamedInputKeysProps} from './types';

/**
* Check if the place matches the search by the place name or description.
* @param search The search string for a place
* @param place The place to check for a match on the search
* @returns true if search is related to place, otherwise it returns false.
*/
function isPlaceMatchForSearch(search: string, place: PredefinedPlace): boolean {
if (!search) {
return true;
}
if (!place) {
return false;
}
const fullSearchSentence = `${place.name ?? ''} ${place.description}`;
return search.split(' ').every((searchTerm) => !searchTerm || (searchTerm && fullSearchSentence.toLocaleLowerCase().includes(searchTerm.toLocaleLowerCase())));
}

// The error that's being thrown below will be ignored until we fork the
// react-native-google-places-autocomplete repo and replace the
Expand All @@ -40,6 +58,7 @@ function AddressSearch(
isLimitedToUSA = false,
label,
maxInputLength,
onFocus,
onBlur,
onInputChange,
onPress,
Expand Down Expand Up @@ -297,10 +316,16 @@ function AddressSearch(
};
}, []);

const filteredPredefinedPlaces = useMemo(() => {
if (!isOffline || !searchValue) {
return predefinedPlaces ?? [];
}
return predefinedPlaces?.filter((predefinedPlace) => isPlaceMatchForSearch(searchValue, predefinedPlace)) ?? [];
}, [isOffline, predefinedPlaces, searchValue]);

const listEmptyComponent = useCallback(
() =>
!!isOffline || !isTyping ? null : <Text style={[styles.textLabel, styles.colorMuted, styles.pv4, styles.ph3, styles.overflowAuto]}>{translate('common.noResultsFound')}</Text>,
[isOffline, isTyping, styles, translate],
() => (!isTyping ? null : <Text style={[styles.textLabel, styles.colorMuted, styles.pv4, styles.ph3, styles.overflowAuto]}>{translate('common.noResultsFound')}</Text>),
[isTyping, styles, translate],
);

const listLoader = useCallback(
Expand Down Expand Up @@ -337,11 +362,10 @@ function AddressSearch(
ref={containerRef}
>
<GooglePlacesAutocomplete
disableScroll
fetchDetails
suppressDefaultStyles
enablePoweredByContainer={false}
predefinedPlaces={predefinedPlaces ?? undefined}
predefinedPlaces={filteredPredefinedPlaces}
listEmptyComponent={listEmptyComponent}
listLoaderComponent={listLoader}
renderHeaderComponent={renderHeaderComponent}
Expand Down Expand Up @@ -384,6 +408,7 @@ function AddressSearch(
shouldSaveDraft,
onFocus: () => {
setIsFocused(true);
onFocus?.();
},
onBlur: (event) => {
if (!isCurrentTargetInsideContainer(event, containerRef)) {
Expand Down Expand Up @@ -413,10 +438,18 @@ function AddressSearch(
}}
styles={{
textInputContainer: [styles.flexColumn],
listView: [StyleUtils.getGoogleListViewStyle(displayListViewBorder), styles.overflowAuto, styles.borderLeft, styles.borderRight, !isFocused && {height: 0}],
listView: [
StyleUtils.getGoogleListViewStyle(displayListViewBorder),
listViewOverflow,
styles.borderLeft,
styles.borderRight,
styles.flexGrow0,
!isFocused && styles.h0,
],
row: [styles.pv4, styles.ph3, styles.overflowAuto],
description: [styles.googleSearchText],
separator: [styles.googleSearchSeparator],
container: [styles.mh100],
}}
numberOfLines={2}
isRowScrollable={false}
Expand All @@ -440,11 +473,13 @@ function AddressSearch(
)
}
placeholder=""
/>
<LocationErrorMessage
onClose={() => setLocationErrorCode(null)}
locationErrorCode={locationErrorCode}
/>
listViewDisplayed
>
<LocationErrorMessage
onClose={() => setLocationErrorCode(null)}
locationErrorCode={locationErrorCode}
/>
</GooglePlacesAutocomplete>
</View>
</ScrollView>
{isFetchingCurrentLocation && <FullScreenLoadingIndicator />}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// eslint-disable-next-line no-restricted-imports
import {defaultStyles} from '@styles/index';

export default defaultStyles.overflowHidden;
4 changes: 4 additions & 0 deletions src/components/AddressSearch/listViewOverflow/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// eslint-disable-next-line no-restricted-imports
import {defaultStyles} from '@styles/index';

export default defaultStyles.overflowAuto;
11 changes: 9 additions & 2 deletions src/components/AddressSearch/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,20 @@ type StreetValue = {
street: string;
};

type PredefinedPlace = Place & {
name?: string;
};

type AddressSearchProps = {
/** The ID used to uniquely identify the input in a Form */
inputID?: string;

/** Saves a draft of the input value when used in a form */
shouldSaveDraft?: boolean;

/** Callback that is called when the text input is focused */
onFocus?: () => void;

/** Callback that is called when the text input is blurred */
onBlur?: () => void;

Expand Down Expand Up @@ -76,7 +83,7 @@ type AddressSearchProps = {
canUseCurrentLocation?: boolean;

/** A list of predefined places that can be shown when the user isn't searching for something */
predefinedPlaces?: Place[] | null;
predefinedPlaces?: PredefinedPlace[] | null;

/** A map of inputID key names */
renamedInputKeys?: RenamedInputKeysProps;
Expand All @@ -96,4 +103,4 @@ type AddressSearchProps = {

type IsCurrentTargetInsideContainerType = (event: FocusEvent | NativeSyntheticEvent<TextInputFocusEventData>, containerRef: RefObject<View | HTMLElement>) => boolean;

export type {CurrentLocationButtonProps, AddressSearchProps, RenamedInputKeysProps, IsCurrentTargetInsideContainerType, StreetValue};
export type {CurrentLocationButtonProps, AddressSearchProps, RenamedInputKeysProps, IsCurrentTargetInsideContainerType, StreetValue, PredefinedPlace};
10 changes: 5 additions & 5 deletions src/components/Form/FormWrapper.tsx
pac-guerreiro marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, {useCallback, useMemo, useRef} from 'react';
import type {RefObject} from 'react';
// eslint-disable-next-line no-restricted-imports
import type {ScrollView as RNScrollView, StyleProp, View, ViewStyle} from 'react-native';
import {Keyboard} from 'react-native';
import type {ScrollView as RNScrollView, StyleProp, ViewStyle} from 'react-native';
import {Keyboard, View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
import FormAlertWithSubmitButton from '@components/FormAlertWithSubmitButton';
Expand Down Expand Up @@ -104,7 +104,7 @@ function FormWrapper({
ref={formContentRef}
style={[style, safeAreaPaddingBottomStyle]}
>
{children}
<View style={styles.flex1}>{children}</View>
pac-guerreiro marked this conversation as resolved.
Show resolved Hide resolved
{isSubmitButtonVisible && (
<FormAlertWithSubmitButton
buttonText={submitButtonText}
Expand Down Expand Up @@ -153,7 +153,7 @@ function FormWrapper({
scrollContextEnabled ? (
<ScrollViewWithContext
style={[styles.w100, styles.flex1]}
contentContainerStyle={styles.flexGrow1}
contentContainerStyle={styles.flex1}
keyboardShouldPersistTaps="handled"
ref={formRef}
>
Expand All @@ -162,7 +162,7 @@ function FormWrapper({
) : (
<ScrollView
style={[styles.w100, styles.flex1]}
contentContainerStyle={styles.flexGrow1}
contentContainerStyle={styles.flex1}
keyboardShouldPersistTaps="handled"
ref={formRef}
>
Expand Down
71 changes: 71 additions & 0 deletions src/hooks/useSubmitButtonVisibility.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import {useEffect, useRef, useState} from 'react';
import {Dimensions} from 'react-native';
import getPlatform from '@libs/getPlatform';
import CONST from '@src/CONST';
import useSafeAreaInsets from './useSafeAreaInsets';
import useThemeStyles from './useThemeStyles';
import useWindowDimensions from './useWindowDimensions';

// Useful when there's a need to hide the submit button, from FormProvider,
pac-guerreiro marked this conversation as resolved.
Show resolved Hide resolved
// to let form content fill the page when virtual keyboard is shown
function useSubmitButtonVisibility() {
const styles = useThemeStyles();
const {windowHeight, isSmallScreenWidth} = useWindowDimensions();
const [isSubmitButtonVisible, setIsSubmitButtonVisible] = useState(true);
const initialWindowHeightRef = useRef(windowHeight);
const isSmallScreenWidthRef = useRef(isSmallScreenWidth);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'm missing something, could you elaborate on why we need initial values (why do we use useRef?)

Copy link
Contributor Author

@pac-guerreiro pac-guerreiro Apr 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eVoloshchak useRef is used here to store the initial value of window height, so that it can be compared with the current window height value to determine if the virtual keyboard is shown or not. About isSmallScreenWidthRef I had to use a ref too because the callback I pass to the Dimensions.addEventListener cannot have dependencies, otherwise multiple event listeners would be set 😄

const {bottom} = useSafeAreaInsets();
const platform = getPlatform();
const isNative = platform === CONST.PLATFORM.IOS || platform === CONST.PLATFORM.ANDROID;
pac-guerreiro marked this conversation as resolved.
Show resolved Hide resolved

neil-marcellini marked this conversation as resolved.
Show resolved Hide resolved
// Web: the submit button is shown when the height of the window is the same or greater,
// otherwise it's hidden
useEffect(() => {
const dimensionsListener = Dimensions.addEventListener('change', ({window}) => {
if (getPlatform() !== CONST.PLATFORM.WEB || !isSmallScreenWidthRef.current) {
pac-guerreiro marked this conversation as resolved.
Show resolved Hide resolved
return;
}

if (window.height < initialWindowHeightRef.current) {
setIsSubmitButtonVisible(false);
return;
}

setIsSubmitButtonVisible(true);
});

return () => dimensionsListener.remove();
}, []);

// Web: the submit button is only shown when the window height is the same or greater,
// so executing this function won't do anything
const showSubmitButton = () => {
if (!isNative) {
return;
}
setIsSubmitButtonVisible(true);
};

// Web: the submit button is only hidden when the window height becomes smaller,
// so executing this function won't do anything
const hideSubmitButton = () => {
if (!isNative) {
return;
}
setIsSubmitButtonVisible(false);
};

// When the submit button is hidden there's need to manually
pac-guerreiro marked this conversation as resolved.
Show resolved Hide resolved
// add its bottom style to the FormProvider style prop,
// otherwise the form content will touch the bottom of the page/screen
const formStyle = !isSubmitButtonVisible && bottom === 0 && styles.mb5;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is duplicated in both files, we can move this outside of useSubmitButtonVisibility by using it directly in IOURequestStepWaypoint

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eVoloshchak

Good point, but I think it would be better for this style to be usable across components. I could extract this into a separate function that receives isSubmitButtonVisible as an argument and returns the style, what do you think?


return {
isSubmitButtonVisible,
showSubmitButton,
hideSubmitButton,
formStyle,
};
}

export default useSubmitButtonVisibility;
2 changes: 1 addition & 1 deletion src/libs/actions/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function saveWaypoint(transactionID: string, index: string, waypoint: RecentWayp
if (!recentWaypointAlreadyExists && waypoint !== null) {
const clonedWaypoints = lodashClone(recentWaypoints);
clonedWaypoints.unshift(waypoint);
Onyx.merge(ONYXKEYS.NVP_RECENT_WAYPOINTS, clonedWaypoints.slice(0, 5));
Onyx.merge(ONYXKEYS.NVP_RECENT_WAYPOINTS, clonedWaypoints.slice(0, CONST.RECENT_WAYPOINTS_NUMBER));
}
}

Expand Down
Loading
Loading