Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit 27f408f

Browse files
author
Krzysztof Jan Modras
authored
News redesign (another iteration) (#872)
1 parent 430ca9e commit 27f408f

File tree

4 files changed

+128
-30
lines changed

4 files changed

+128
-30
lines changed

ReactNative/js/components/SpeedDial.jsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ const getStyles = theme => ({
1313
alignItems: 'center',
1414
},
1515
circle: {
16-
borderColor: theme.separatorColor,
17-
borderWidth: 1,
1816
padding: 20,
1917
borderRadius: 60,
18+
backgroundColor: '#ffffff30',
2019
},
2120
label: {
2221
marginTop: 5,
@@ -37,7 +36,7 @@ const getStyles = theme => ({
3736
pinIcon: {
3837
width: 12,
3938
height: 12,
40-
color: theme.textColor,
39+
color: '#ffffff',
4140
},
4241
});
4342

ReactNative/js/screens/Home/components/News.jsx

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
StyleSheet,
66
Image,
77
TouchableWithoutFeedback,
8+
Text,
89
} from 'react-native';
910
import ListItem from '../../../components/ListItem';
1011
import ThemeContext from '../../../contexts/theme';
@@ -17,8 +18,10 @@ const getStyles = theme =>
1718
paddingTop: 30,
1819
},
1920
image: {
20-
height: 200,
21-
marginBottom: 10,
21+
height: 100,
22+
width: 150,
23+
flexShrink: 0,
24+
marginLeft: 10,
2225
},
2326
item: {
2427
marginBottom: 20,
@@ -28,6 +31,16 @@ const getStyles = theme =>
2831
backgroundColor: theme.separatorColor,
2932
height: 1,
3033
},
34+
description: {
35+
flex: 1,
36+
color: theme.textColor,
37+
fontSize: 12,
38+
},
39+
secondRow: {
40+
marginTop: 5,
41+
flex: 1,
42+
flexDirection: 'row',
43+
},
3144
});
3245

3346
const openLink = url => NativeModules.BrowserActions.openLink(url, '');
@@ -53,7 +66,7 @@ const useNews = newsModule => {
5366
return data;
5467
};
5568

56-
const HiddableImage = (props) => {
69+
const HiddableImage = props => {
5770
const { style, source } = props;
5871
const [isHidden, setHidden] = useState(false, [source]);
5972
const hide = useCallback(() => setHidden(true), [setHidden]);
@@ -62,10 +75,18 @@ const HiddableImage = (props) => {
6275
[isHidden],
6376
);
6477
return (
65-
<Image {...props} style={[style, hiddenStyle]} source={{ uri: source }} onError={hide} />
78+
<Image
79+
// eslint-disable-next-line react/jsx-props-no-spreading
80+
{...props}
81+
style={[style, hiddenStyle]}
82+
source={{ uri: source }}
83+
onError={hide}
84+
/>
6685
);
6786
};
6887

88+
const noop = () => {};
89+
6990
export default function News({ newsModule, isImagesEnabled }) {
7091
const theme = useContext(ThemeContext);
7192
const news = useNews(newsModule);
@@ -75,7 +96,6 @@ export default function News({ newsModule, isImagesEnabled }) {
7596
if (news.length === 0) {
7697
return null;
7798
}
78-
7999
/* eslint-disable prettier/prettier */
80100
return (
81101
<View style={styles.container}>
@@ -85,20 +105,25 @@ export default function News({ newsModule, isImagesEnabled }) {
85105
style={styles.item}
86106
key={item.url}
87107
>
88-
{isImagesEnabled && item.imageUrl &&
89-
<TouchableWithoutFeedback
90-
onPress={() => openLink(item.url)}
91-
>
92-
<HiddableImage style={styles.image} source={item.imageUrl} />
93-
</TouchableWithoutFeedback>
94-
}
95-
<ListItem
96-
url={item.url}
97-
title={item.title}
98-
displayUrl={item.domain}
99-
label={item.breaking_label ? NativeModules.LocaleConstants['ActivityStream.News.BreakingLabel'] : null}
100-
onPress={() => openLink(item.url)}
101-
/>
108+
<TouchableWithoutFeedback onPress={() => openLink(item.url)}>
109+
<View>
110+
<ListItem
111+
url={item.url}
112+
title={item.title}
113+
displayUrl={item.domain}
114+
label={item.breaking_label ? NativeModules.LocaleConstants['ActivityStream.News.BreakingLabel'] : null}
115+
onPress={noop}
116+
/>
117+
<View style={styles.secondRow}>
118+
<Text style={styles.description} allowFontScaling={false}>
119+
{item.description}
120+
</Text>
121+
{isImagesEnabled && item.imageUrl &&
122+
<HiddableImage style={styles.image} source={item.imageUrl} />
123+
}
124+
</View>
125+
</View>
126+
</TouchableWithoutFeedback>
102127
<View style={styles.separator} />
103128
</View>
104129
))}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import React from 'react';
2+
import { TouchableWithoutFeedback, View, Text, StyleSheet } from 'react-native';
3+
import NativeDrawable from '../../../components/NativeDrawable';
4+
5+
const styles = StyleSheet.create({
6+
wrapper: {
7+
width: '100%',
8+
},
9+
button: {
10+
alignSelf: 'flex-end',
11+
flexDirection: 'row',
12+
},
13+
buttonText: {
14+
color: 'white',
15+
fontSize: 15,
16+
marginRight: 5,
17+
},
18+
buttonIcon: {
19+
color: '#ffffff',
20+
height: 20,
21+
width: 20,
22+
transform: [{ rotate: '-90deg' }],
23+
},
24+
});
25+
26+
export default ({ scrollToNews }: { scrollToNews: any }) => {
27+
return (
28+
<View style={styles.wrapper}>
29+
<TouchableWithoutFeedback onPress={scrollToNews}>
30+
<View style={styles.button}>
31+
<Text style={styles.buttonText}>News</Text>
32+
<NativeDrawable
33+
style={styles.buttonIcon}
34+
source="nav-back"
35+
color={styles.buttonIcon.color}
36+
/>
37+
</View>
38+
</TouchableWithoutFeedback>
39+
</View>
40+
);
41+
};

ReactNative/js/screens/Home/index.jsx

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
1-
import React, { useMemo } from 'react';
1+
import React, { useMemo, useRef, useCallback, useState } from 'react';
22
import {
33
Dimensions,
44
NativeModules,
55
ScrollView,
66
StyleSheet,
77
View,
88
Image,
9+
findNodeHandle,
910
} from 'react-native';
1011
import { parse } from 'tldts';
1112
import ToolbarArea from '../../components/ToolbarArea';
1213
import News from './components/News';
1314
import SpeedDialRow from './components/SpeedDialsRow';
1415
import UrlBar from './components/UrlBar';
1516
import Background from './components/Background';
17+
import NewsToolbar from './components/NewsToolbar';
1618

1719
const hideKeyboard = () => NativeModules.BrowserActions.hideKeyboard();
1820

19-
const getStyles = () =>
20-
StyleSheet.create({
21+
const getStyles = () => {
22+
const maxWidth = Math.min(
23+
Dimensions.get('window').width,
24+
Dimensions.get('window').height,
25+
);
26+
27+
return StyleSheet.create({
2128
safeArea: {
2229
flex: 1,
2330
},
@@ -36,12 +43,15 @@ const getStyles = () =>
3643
flexDirection: 'column',
3744
justifyContent: 'space-evenly',
3845
},
46+
newsToolbarWrapper: {
47+
width: maxWidth,
48+
paddingHorizontal: 20,
49+
marginBottom: 20,
50+
alignSelf: 'center',
51+
},
3952
newsWrapper: {
4053
flex: 1,
41-
width: Math.min(
42-
Dimensions.get('window').width,
43-
Dimensions.get('window').height,
44-
),
54+
width: maxWidth,
4555
alignSelf: 'center',
4656
paddingHorizontal: 20,
4757
},
@@ -65,6 +75,7 @@ const getStyles = () =>
6575
height: 80,
6676
},
6777
});
78+
};
6879

6980
export default function Home({
7081
speedDials,
@@ -75,6 +86,9 @@ export default function Home({
7586
height,
7687
toolbarHeight,
7788
}) {
89+
const [showNewsToolbar, setShowNewsToolbar] = useState(true);
90+
const scrollViewElement = useRef(null);
91+
const newsElement = useRef(null);
7892
const styles = getStyles();
7993
const [firstRow, secondRow] = useMemo(() => {
8094
const pinnedDomains = new Set([
@@ -87,8 +101,23 @@ export default function Home({
87101
return [dials.slice(0, 4), dials.slice(4, 8)];
88102
}, [pinnedSites, speedDials]);
89103

104+
const scrollToNews = useCallback(() => {
105+
if (!scrollViewElement.current || !newsElement.current) {
106+
return;
107+
}
108+
scrollViewElement.current.scrollTo({ x: 0, y: 100 });
109+
newsElement.current.measureLayout(
110+
findNodeHandle(scrollViewElement.current),
111+
(x, y) => {
112+
scrollViewElement.current.scrollTo({ x, y });
113+
},
114+
);
115+
setShowNewsToolbar(false);
116+
}, [scrollViewElement]);
117+
90118
return (
91119
<ScrollView
120+
ref={scrollViewElement}
92121
style={styles.container}
93122
onScroll={hideKeyboard}
94123
scrollEventThrottle={1}
@@ -113,10 +142,14 @@ export default function Home({
113142
<SpeedDialRow dials={secondRow} />
114143
</View>
115144
</View>
145+
146+
<View style={styles.newsToolbarWrapper}>
147+
{showNewsToolbar && <NewsToolbar scrollToNews={scrollToNews} />}
148+
</View>
116149
<ToolbarArea height={toolbarHeight} />
117150
</Background>
118151
{isNewsEnabled && (
119-
<View style={styles.newsWrapper}>
152+
<View style={styles.newsWrapper} ref={newsElement}>
120153
<News newsModule={newsModule} isImagesEnabled={isNewsImagesEnabled} />
121154
</View>
122155
)}

0 commit comments

Comments
 (0)