forked from NativeScript/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHomeScreen.tsx
More file actions
71 lines (66 loc) · 2.22 KB
/
HomeScreen.tsx
File metadata and controls
71 lines (66 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import * as React from "react";
import { NSVElement, ListView } from "react-nativescript";
import { RouteProp } from '@react-navigation/core';
import { ItemEventData, Page } from '@nativescript/core';
import { FrameNavigationProp } from "react-nativescript-navigation";
import { MainStackParamList } from "./NavigationParamList";
import { FlickService } from "../services/flick.service";
import { FlickModel } from "../models";
type HomeScreenProps = {
route: RouteProp<MainStackParamList, "Home">,
navigation: FrameNavigationProp<MainStackParamList, "Home">,
}
export function HomeScreen({ navigation }: HomeScreenProps) {
const pageRef = React.useRef<NSVElement<Page>>(null);
const flicks = FlickService.getFlicks();
const cellFactory = (flick: FlickModel) => {
return (
<gridLayout
height="280"
borderRadius="10"
className="bg-secondary"
rows="*, auto, auto"
columns="*"
margin="5 10"
padding="0">
<image
row="0"
margin="0"
stretch="aspectFill"
src={flick.image}/>
<label
row="1"
margin="10 10 0 10"
fontWeight="700"
className="text-primary"
fontSize="18"
text={flick.title}/>
<label
row="2"
margin="0 10 10 10"
className="text-secondary"
fontSize="14"
textWrap="true"
text={flick.description}/>
</gridLayout>
)
};
const onItemTap = (args: ItemEventData) => {
const index = args.index;
const flick = flicks[index];
navigation.navigate('Details', {
flickId: flick.id,
})
};
return (
<stackLayout height="100%">
<ListView
items={flicks}
cellFactory={cellFactory}
onItemTap={onItemTap}
separatorColor="transparent"
height="100%"
/>
</stackLayout>
);
}