Swipeable actions!
This commit is contained in:
138
app/index.tsx
138
app/index.tsx
@@ -1,44 +1,98 @@
|
||||
import {FlatList, Text, View, ColorValue, ListRenderItemInfo} from "react-native";
|
||||
// @ts-ignore
|
||||
import SwipeableFlatList from 'react-native-swipeable-list';
|
||||
import {StyleSheet, Text, View, ColorValue, ListRenderItemInfo, TouchableOpacity} from "react-native";
|
||||
import {RowMap, SwipeListView} from "react-native-swipe-list-view";
|
||||
|
||||
const servers: Server[] = [
|
||||
{
|
||||
name: "Test Data Server",
|
||||
domain: "localhost",
|
||||
computers: [
|
||||
{
|
||||
key: 0,
|
||||
name: "Test PC",
|
||||
emoji: "💻",
|
||||
background_color: '#D9D9D9',
|
||||
mac_address: "00:1A:2B:3C:4D:5E",
|
||||
},
|
||||
{
|
||||
key: 1,
|
||||
name: "Another PC in the basement",
|
||||
emoji: "💻",
|
||||
background_color: '#D9D9D9',
|
||||
mac_address: "00:1A:2B:3C:4D:5E",
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
export default function Index() {
|
||||
return (
|
||||
<View style={{
|
||||
backgroundColor: "#FFFFFF",
|
||||
}}>
|
||||
<ComputerList computers={[
|
||||
{
|
||||
name: "Test PC",
|
||||
emoji: "💻",
|
||||
background_color: '#D9D9D9',
|
||||
mac_address: "00:1A:2B:3C:4D:5E",
|
||||
},
|
||||
{
|
||||
name: "Another PC in the basement",
|
||||
emoji: "💻",
|
||||
background_color: '#D9D9D9',
|
||||
mac_address: "00:1A:2B:3C:4D:5E",
|
||||
}
|
||||
]}/>
|
||||
</View>
|
||||
<ComputerList computers={servers[0].computers}/>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
computerElement: {
|
||||
display: "flex",
|
||||
flexDirection: "row",
|
||||
paddingHorizontal: 24,
|
||||
paddingVertical: 14,
|
||||
gap: 32,
|
||||
backgroundColor: '#FFFFFF'
|
||||
},
|
||||
computerName: {
|
||||
fontSize: 18,
|
||||
justifyContent: "flex-start",
|
||||
},
|
||||
computerSubtitle: {
|
||||
fontSize: 12,
|
||||
justifyContent: "flex-start",
|
||||
color: '#979797'
|
||||
},
|
||||
backTextWhite: {
|
||||
color: '#FFF',
|
||||
},
|
||||
rowBack: {
|
||||
alignItems: 'center',
|
||||
backgroundColor: '#DDD',
|
||||
flex: 1,
|
||||
flexDirection: 'row',
|
||||
justifyContent: 'space-between',
|
||||
paddingLeft: 15,
|
||||
},
|
||||
backRightBtn: {
|
||||
alignItems: 'center',
|
||||
bottom: 0,
|
||||
justifyContent: 'center',
|
||||
position: 'absolute',
|
||||
top: 0,
|
||||
width: 75,
|
||||
},
|
||||
backRightBtnRight: {
|
||||
backgroundColor: 'red',
|
||||
right: 0,
|
||||
},
|
||||
});
|
||||
|
||||
function ComputerList(computers: { computers: Computer[] }) {
|
||||
return (
|
||||
<View>
|
||||
<FlatList style={{
|
||||
borderRadius: 25,
|
||||
}} data={computers.computers} renderItem={({item}: ListRenderItemInfo<Computer>) =>
|
||||
<View style={{
|
||||
display: "flex",
|
||||
flexDirection: "row",
|
||||
paddingHorizontal: 15,
|
||||
paddingVertical: 15,
|
||||
gap: 60,
|
||||
backgroundColor: '#FFFFFF'
|
||||
const renderHiddenItem = (data: ListRenderItemInfo<Computer>, rowMap: RowMap<Computer>) => (
|
||||
<View style={styles.rowBack}>
|
||||
<TouchableOpacity
|
||||
style={[styles.backRightBtn, styles.backRightBtnRight]}
|
||||
onPress={() => {
|
||||
//TODO: remove it from storage
|
||||
}}>
|
||||
<Text style={styles.backTextWhite}>Delete</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
);
|
||||
|
||||
return (
|
||||
<SwipeListView style={{
|
||||
// borderRadius: 25,
|
||||
}}
|
||||
data={computers.computers}
|
||||
renderItem={({item}: ListRenderItemInfo<Computer>) =>
|
||||
<View style={styles.computerElement}>
|
||||
<View style={{
|
||||
width: 65,
|
||||
height: 65,
|
||||
@@ -53,23 +107,16 @@ function ComputerList(computers: { computers: Computer[] }) {
|
||||
</View>
|
||||
<View style={{
|
||||
flexDirection: "column",
|
||||
gap: 0,
|
||||
gap: 3,
|
||||
padding: 0,
|
||||
justifyContent: "center",
|
||||
}}>
|
||||
<Text style={{
|
||||
fontSize: 18,
|
||||
justifyContent: "flex-start",
|
||||
}}>{item.name}</Text>
|
||||
<Text style={{
|
||||
fontSize: 12,
|
||||
justifyContent: "flex-start",
|
||||
color: '#979797'
|
||||
}}>{item.mac_address}</Text>
|
||||
<Text style={styles.computerName}>{item.name}</Text>
|
||||
<Text style={styles.computerSubtitle}>{item.mac_address}</Text>
|
||||
</View>
|
||||
</View>
|
||||
}/>
|
||||
</View>
|
||||
} rightOpenValue={-75} renderHiddenItem={renderHiddenItem}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -80,6 +127,7 @@ type Server = {
|
||||
}
|
||||
|
||||
type Computer = {
|
||||
key: number,
|
||||
name: string,
|
||||
emoji: string,
|
||||
background_color: ColorValue,
|
||||
|
||||
15
package-lock.json
generated
15
package-lock.json
generated
@@ -30,7 +30,7 @@
|
||||
"react-native-reanimated": "~3.16.1",
|
||||
"react-native-safe-area-context": "4.12.0",
|
||||
"react-native-screens": "~4.4.0",
|
||||
"react-native-swipeable-list": "^0.1.2",
|
||||
"react-native-swipe-list-view": "^3.2.9",
|
||||
"react-native-web": "~0.19.13",
|
||||
"react-native-webview": "13.12.5"
|
||||
},
|
||||
@@ -11748,14 +11748,15 @@
|
||||
"react-native": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/react-native-swipeable-list": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "https://registry.npmjs.org/react-native-swipeable-list/-/react-native-swipeable-list-0.1.2.tgz",
|
||||
"integrity": "sha512-FDeFLByUep3m3xuwS/ZkktxL7Xzg90XnKoo+KLTF04jiddyVZQMnXTHG8O4pyiEtg/swcBlT6XUktV+/KTVNXQ==",
|
||||
"node_modules/react-native-swipe-list-view": {
|
||||
"version": "3.2.9",
|
||||
"resolved": "https://registry.npmjs.org/react-native-swipe-list-view/-/react-native-swipe-list-view-3.2.9.tgz",
|
||||
"integrity": "sha512-SjAEuHc/D6ovp+RjDUhfNmw6NYOntdT7+GFhfMGfP/BSLMuMWynpzJy9GKQeyB8sI78T6Lzip21TVbongOg1Mw==",
|
||||
"license": "MIT",
|
||||
"peerDependencies": {
|
||||
"react": ">=16.11.0",
|
||||
"react-native": ">=0.61.4"
|
||||
"prop-types": ">=15.5.0",
|
||||
"react": ">=0.14.8",
|
||||
"react-native": ">=0.23.1"
|
||||
}
|
||||
},
|
||||
"node_modules/react-native-web": {
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
"react-native-reanimated": "~3.16.1",
|
||||
"react-native-safe-area-context": "4.12.0",
|
||||
"react-native-screens": "~4.4.0",
|
||||
"react-native-swipeable-list": "^0.1.2",
|
||||
"react-native-swipe-list-view": "^3.2.9",
|
||||
"react-native-web": "~0.19.13",
|
||||
"react-native-webview": "13.12.5"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user