-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fix/confirmation-ui-adjustments
- Loading branch information
Showing
27 changed files
with
774 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
app/components/UI/NetworkSelectorList/NetworkSelectorList.styles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { StyleSheet } from 'react-native'; | ||
|
||
const styleSheet = () => | ||
StyleSheet.create({ | ||
networkItemContainer: { | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
padding: 10, | ||
}, | ||
networkAvatar: { | ||
marginHorizontal: 10, | ||
}, | ||
networkName: { | ||
flex: 1, | ||
fontSize: 16, | ||
}, | ||
networkList: { marginHorizontal: 6 }, | ||
}); | ||
|
||
export default styleSheet; |
114 changes: 114 additions & 0 deletions
114
app/components/UI/NetworkSelectorList/NetworkSelectorList.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// Third party dependencies. | ||
import React, { useCallback, useRef } from 'react'; | ||
import { ListRenderItem, ImageSourcePropType } from 'react-native'; | ||
import { FlatList } from 'react-native-gesture-handler'; | ||
|
||
// External dependencies. | ||
import { useStyles } from '../../../component-library/hooks'; | ||
import { | ||
AvatarSize, | ||
AvatarVariant, | ||
} from '../../../component-library/components/Avatars/Avatar'; | ||
import Cell, { | ||
CellVariant, | ||
} from '../../../component-library/components/Cells/Cell'; | ||
|
||
// Internal dependencies. | ||
import { | ||
NetworkConnectMultiSelectorProps, | ||
Network, | ||
} from './NetworkSelectorList.types'; | ||
import styleSheet from './NetworkSelectorList.styles'; | ||
|
||
const NetworkSelectorList = ({ | ||
onSelectNetwork, | ||
networks = [], | ||
isLoading = false, | ||
selectedNetworkIds, | ||
isMultiSelect = true, | ||
renderRightAccessory, | ||
isSelectionDisabled, | ||
isAutoScrollEnabled = true, | ||
...props | ||
}: NetworkConnectMultiSelectorProps) => { | ||
const networksLengthRef = useRef<number>(0); | ||
const { styles } = useStyles(styleSheet, {}); | ||
|
||
/** | ||
* Ref for the FlatList component. | ||
* The type of the ref is not explicitly defined. | ||
*/ | ||
// TODO: Replace "any" with type | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const networkListRef = useRef<any>(null); | ||
|
||
const getKeyExtractor = ({ id }: Network) => id; | ||
|
||
const renderNetworkItem: ListRenderItem<Network> = useCallback( | ||
({ item: { id, name, isSelected, imageSource } }) => { | ||
const isDisabled = isLoading || isSelectionDisabled; | ||
const cellVariant = isMultiSelect | ||
? CellVariant.MultiSelect | ||
: CellVariant.Select; | ||
let isSelectedNetwork = isSelected; | ||
if (selectedNetworkIds) { | ||
isSelectedNetwork = selectedNetworkIds.includes(id); | ||
} | ||
|
||
return ( | ||
<Cell | ||
variant={cellVariant} | ||
isSelected={isSelectedNetwork} | ||
title={name} | ||
onPress={() => onSelectNetwork?.(id, isSelectedNetwork)} | ||
avatarProps={{ | ||
variant: AvatarVariant.Network, | ||
name, | ||
imageSource: imageSource as ImageSourcePropType, | ||
size: AvatarSize.Sm, | ||
}} | ||
disabled={isDisabled} | ||
style={styles.networkItemContainer} | ||
> | ||
{renderRightAccessory?.(id, name)} | ||
</Cell> | ||
); | ||
}, | ||
[ | ||
isLoading, | ||
selectedNetworkIds, | ||
renderRightAccessory, | ||
isSelectionDisabled, | ||
onSelectNetwork, | ||
styles, | ||
isMultiSelect, | ||
], | ||
); | ||
|
||
const onContentSizeChanged = useCallback(() => { | ||
if (!networks.length || !isAutoScrollEnabled) return; | ||
if (networksLengthRef.current !== networks.length) { | ||
const selectedNetwork = networks.find(({ isSelected }) => isSelected); | ||
networkListRef?.current?.scrollToOffset({ | ||
offset: selectedNetwork?.yOffset ?? 0, | ||
animated: false, | ||
}); | ||
networksLengthRef.current = networks.length; | ||
} | ||
}, [networks, isAutoScrollEnabled]); | ||
|
||
return ( | ||
<FlatList | ||
style={styles.networkList} | ||
ref={networkListRef} | ||
onContentSizeChange={onContentSizeChanged} | ||
data={networks} | ||
keyExtractor={getKeyExtractor} | ||
renderItem={renderNetworkItem} | ||
initialNumToRender={999} | ||
{...props} | ||
/> | ||
); | ||
}; | ||
|
||
export default NetworkSelectorList; |
20 changes: 20 additions & 0 deletions
20
app/components/UI/NetworkSelectorList/NetworkSelectorList.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { ImageSourcePropType } from 'react-native'; | ||
export interface Network { | ||
id: string; | ||
name: string; | ||
rpcUrl: string; | ||
isSelected: boolean; | ||
yOffset?: number; | ||
imageSource: ImageSourcePropType; | ||
} | ||
|
||
export interface NetworkConnectMultiSelectorProps { | ||
onSelectNetwork?: (id: string, isSelected: boolean) => void; | ||
networks?: Network[]; | ||
isLoading?: boolean; | ||
selectedNetworkIds?: string[]; | ||
isMultiSelect?: boolean; | ||
renderRightAccessory?: (id: string, name: string) => React.ReactNode; | ||
isSelectionDisabled?: boolean; | ||
isAutoScrollEnabled?: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...ts/Views/NetworkConnect/NetworkConnectMultiSelector/NetworkConnectMultiSelector.styles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { StyleSheet } from 'react-native'; | ||
import { isMutichainVersion1Enabled } from '../../../../util/networks'; | ||
|
||
const styleSheet = () => | ||
StyleSheet.create({ | ||
bottomSheetContainer: { | ||
height: '100%', | ||
}, | ||
bodyContainer: { | ||
paddingHorizontal: 16, | ||
}, | ||
buttonsContainer: { | ||
marginTop: isMutichainVersion1Enabled ? 0 : 24, | ||
marginBottom: 16, | ||
}, | ||
updateButtonContainer: { flexDirection: 'row' }, | ||
buttonPositioning: { flex: 1 }, | ||
disabledOpacity: { | ||
opacity: 0.5, | ||
}, | ||
selectAllContainer: { | ||
marginLeft: 0, | ||
marginVertical: 12, | ||
}, | ||
disconnectAll: { | ||
flexDirection: 'column', | ||
alignItems: 'center', | ||
}, | ||
helpText: { | ||
margin: 16, | ||
}, | ||
disconnectAllButton: { | ||
flexDirection: 'row', | ||
}, | ||
}); | ||
|
||
export default styleSheet; |
Oops, something went wrong.