Skip to content

Commit 6affd90

Browse files
Windows accessibility - code architecture & layout adjustments (#31)
* Use Settings to listen for theme and language * Use x:Name for navigation items tag The `Name` property is used to control the item of a XAML layout in the code-behind of a Page. Thsi way it is possible to set its style and properties when they are changed in the Settings. * Adjust layout of screens for font in Settings When text size changes and the font is replaced, the text needs to have enough space to fit in the layout after Settings. To do that some `styles` have been modified to let the text adjust easily to Settings. * Apply ESLint fixes
1 parent ddcd8d6 commit 6affd90

8 files changed

Lines changed: 134 additions & 26 deletions

File tree

src/CreateNotePanel.tsx

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
TextInput,
1212
View,
1313
Button,
14+
NativeEventEmitter,
1415
} from 'react-native';
1516
import Colors from './Resources/Colors';
1617
import * as dict from './Resources/Dictionary';
@@ -21,14 +22,22 @@ interface Props {}
2122
interface State {
2223
title: string;
2324
message: string;
25+
language: number;
26+
theme: number;
2427
}
2528

29+
const SettingsNotificationModuleEventEmitter = new NativeEventEmitter(
30+
NativeModules.Database,
31+
);
32+
2633
class CreateNotePanel extends React.Component<Props, State> {
2734
constructor(props: Props) {
2835
super(props);
2936
this.state = {
3037
title: '',
3138
message: '',
39+
language: 0,
40+
theme: 0,
3241
};
3342
}
3443

@@ -62,6 +71,21 @@ class CreateNotePanel extends React.Component<Props, State> {
6271
}
6372
};
6473

74+
componentDidMount() {
75+
SettingsNotificationModuleEventEmitter.addListener(
76+
'LanguageChanged',
77+
(result) => {
78+
this.setState({language: result});
79+
},
80+
);
81+
SettingsNotificationModuleEventEmitter.addListener(
82+
'ThemeChanged',
83+
(result) => {
84+
this.setState({theme: result});
85+
},
86+
);
87+
}
88+
6589
createButtonPressed = () => {
6690
NativeModules.Database.writeNote(
6791
this.state.title,
@@ -120,6 +144,7 @@ const styles = StyleSheet.create({
120144
borderBottomWidth: 1,
121145
borderTopWidth: 0,
122146
width: '90%',
147+
height: 'auto',
123148
borderColor: Colors.noteTextPanelBorder,
124149
fontWeight: 'bold',
125150
marginTop: 30,
@@ -128,7 +153,7 @@ const styles = StyleSheet.create({
128153
borderWidth: 0.2,
129154
margin: 10,
130155
width: '90%',
131-
height: '85%',
156+
flexGrow: 1,
132157
borderColor: Colors.noteTextPanelBorder,
133158
alignContent: 'center',
134159
textAlignVertical: 'center',
@@ -139,6 +164,7 @@ const styles = StyleSheet.create({
139164
justifyContent: 'space-around',
140165
width: '60%',
141166
maxHeight: 35,
167+
margin: 10,
142168
},
143169
});
144170

src/NoteWidgetDetailsPanel.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,25 @@ import {
1111
TextInput,
1212
View,
1313
Button,
14+
NativeEventEmitter,
1415
} from 'react-native';
1516
import Colors from './Resources/Colors';
1617
import * as dictionary from './Resources/Dictionary';
1718
import * as theming from './Resources/Theming/ThemeHOC';
1819

20+
const SettingsNotificationModuleEventEmitter = new NativeEventEmitter(
21+
NativeModules.Database,
22+
);
23+
1924
interface Props {}
2025

2126
interface State {
2227
id: number;
2328
title: string;
2429
message: string;
2530
isEditing: boolean;
31+
language: number;
32+
theme: number;
2633
}
2734

2835
class NoteWidgetDetailsPanel extends React.Component<Props, State> {
@@ -33,6 +40,8 @@ class NoteWidgetDetailsPanel extends React.Component<Props, State> {
3340
title: '',
3441
message: '',
3542
isEditing: false,
43+
language: 0,
44+
theme: 0,
3645
};
3746
}
3847

@@ -50,6 +59,18 @@ class NoteWidgetDetailsPanel extends React.Component<Props, State> {
5059
`Could not find the opened note\n${error.message}`,
5160
);
5261
});
62+
SettingsNotificationModuleEventEmitter.addListener(
63+
'LanguageChanged',
64+
(result) => {
65+
this.setState({language: result});
66+
},
67+
);
68+
SettingsNotificationModuleEventEmitter.addListener(
69+
'ThemeChanged',
70+
(result) => {
71+
this.setState({theme: result});
72+
},
73+
);
5374
}
5475

5576
titleOnChange = (text: string) => {

src/NotesMainPanel.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
AppRegistry,
99
Dimensions,
1010
FlatList,
11+
NativeEventEmitter,
1112
NativeModules,
1213
StyleSheet,
1314
Text,
@@ -18,6 +19,9 @@ import Dictionary from './Resources/Dictionary';
1819
import * as theming from './Resources/Theming/ThemeHOC';
1920

2021
const noteWidgetWidth = 300;
22+
const SettingsNotificationModuleEventEmitter = new NativeEventEmitter(
23+
NativeModules.Database,
24+
);
2125

2226
function calculateColumnWidth() {
2327
return Math.floor(Dimensions.get('window').width / noteWidgetWidth);
@@ -34,6 +38,8 @@ interface INote {
3438
interface State {
3539
notes: Array<INote>;
3640
columns: number;
41+
language: number;
42+
theme: number;
3743
}
3844

3945
class NotesMainPanel extends React.Component<Props, State> {
@@ -42,6 +48,8 @@ class NotesMainPanel extends React.Component<Props, State> {
4248
this.state = {
4349
notes: [],
4450
columns: calculateColumnWidth(),
51+
language: 0,
52+
theme: 0,
4553
};
4654
}
4755

@@ -54,6 +62,18 @@ class NotesMainPanel extends React.Component<Props, State> {
5462
componentDidMount() {
5563
this.getDataFromDatabase();
5664
Dimensions.addEventListener('change', this.onChange);
65+
SettingsNotificationModuleEventEmitter.addListener(
66+
'LanguageChanged',
67+
(result) => {
68+
this.setState({language: result});
69+
},
70+
);
71+
SettingsNotificationModuleEventEmitter.addListener(
72+
'ThemeChanged',
73+
(result) => {
74+
this.setState({theme: result});
75+
},
76+
);
5777
}
5878

5979
componentWillUnmount() {
@@ -130,6 +150,9 @@ const styles = StyleSheet.create({
130150
flex: 1,
131151
justifyContent: 'center',
132152
alignItems: 'center',
153+
textAlign: 'center',
154+
alignContent: 'center',
155+
height: '100%',
133156
},
134157
logoText: {
135158
fontSize: 35,

src/Resources/Dictionary.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import {Alert, NativeModules, Text} from 'react-native';
2+
import {NativeModules, Text, NativeEventEmitter} from 'react-native';
33
import en from './Localization/en.json';
44
import pl from './Localization/pl.json';
55

@@ -11,6 +11,10 @@ export interface Props {
1111
export const languages = [en, pl];
1212
export var languageNum: number;
1313

14+
const LanguageNotificationModuleEventEmitter = new NativeEventEmitter(
15+
NativeModules.Database,
16+
);
17+
1418
export function getTextByKey(textLabel: string): string {
1519
let index = 0;
1620
if (languageNum < languages.length) index = languageNum;
@@ -33,17 +37,17 @@ export class Dictionary extends React.Component<Props, State> {
3337
};
3438
}
3539

36-
getText = () => {
37-
NativeModules.Database.getLanguageValue()
38-
.then((result: number) => {
40+
componentDidMount() {
41+
LanguageNotificationModuleEventEmitter.addListener(
42+
'LanguageChanged',
43+
(result) => {
3944
this.setState({languageValue: result});
4045
languageNum = result;
41-
return result;
42-
})
43-
.catch((error: Error) => {
44-
Alert.alert(`ERROR: ${error.message}`);
45-
});
46+
},
47+
);
48+
}
4649

50+
getText = () => {
4751
switch (this.state.languageValue) {
4852
case 0: {
4953
let enDictionary = new Map(Object.entries(en));

src/Resources/Theming/ThemeHOC.tsx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import {NativeModules, View} from 'react-native';
2+
import {NativeModules, NativeEventEmitter, View} from 'react-native';
33

44
interface Props {
55
style: any;
@@ -10,6 +10,10 @@ interface State {
1010
style: any;
1111
}
1212

13+
const ThemeNotificationModuleEventEmitter = new NativeEventEmitter(
14+
NativeModules.Database,
15+
);
16+
1317
export function applyTheming(style: any) {
1418
let theme = 0;
1519
const getTheme = async () => {
@@ -42,19 +46,16 @@ export class ThemedView extends React.Component<Props, State> {
4246
};
4347
}
4448

45-
requireTheming = (style: any) => {
46-
const getTheme = async () => {
47-
await NativeModules.Database.getThemeValue()
48-
.then((result: number) => {
49-
this.setState({themeValue: result});
50-
return result;
51-
})
52-
.catch((error: Error) => {
53-
console.log(`ERROR: ${error.message}`);
54-
});
55-
};
49+
componentDidMount() {
50+
ThemeNotificationModuleEventEmitter.addListener(
51+
'ThemeChanged',
52+
(result) => {
53+
this.setState({themeValue: result});
54+
},
55+
);
56+
}
5657

57-
getTheme();
58+
requireTheming = (style: any) => {
5859
switch (this.state.themeValue) {
5960
case 0:
6061
return {...style, backgroundColor: 'transparent'};

src/ToDoListPanel.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import {
1010
TextInput,
1111
Button,
1212
View,
13+
NativeEventEmitter,
14+
NativeModules,
1315
} from 'react-native';
1416
import DateTimePicker from '@react-native-community/datetimepicker';
1517
import TaskWidget from './Widgets/TaskWidget';
@@ -30,8 +32,14 @@ interface State {
3032
number: number;
3133
message: string;
3234
selectedDate: Date | undefined;
35+
language: number;
36+
theme: number;
3337
}
3438

39+
const SettingsNotificationModuleEventEmitter = new NativeEventEmitter(
40+
NativeModules.Database,
41+
);
42+
3543
class ToDoListPanel extends React.Component<Props, State> {
3644
constructor(props: Props) {
3745
super(props);
@@ -40,9 +48,26 @@ class ToDoListPanel extends React.Component<Props, State> {
4048
number: 0,
4149
message: '',
4250
selectedDate: new Date(),
51+
language: 0,
52+
theme: 0,
4353
};
4454
}
4555

56+
componentDidMount() {
57+
SettingsNotificationModuleEventEmitter.addListener(
58+
'LanguageChanged',
59+
(result) => {
60+
this.setState({language: result});
61+
},
62+
);
63+
SettingsNotificationModuleEventEmitter.addListener(
64+
'ThemeChanged',
65+
(result) => {
66+
this.setState({theme: result});
67+
},
68+
);
69+
}
70+
4671
onChange = (event: Event, selectedDate?: Date) => {
4772
const currentDate = selectedDate;
4873
this.setState({selectedDate: currentDate});

windows/ReactNativeNotes/MainPage.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,19 @@
3030

3131
<muxc:NavigationView.MenuItems>
3232

33-
<muxc:NavigationViewItem Content="Create" Tag="CreateNotePage" Foreground="White" Margin="0,5,0,5">
33+
<muxc:NavigationViewItem x:Name="CreateNotePageNavItem" Content="Create" Tag="CreateNotePage" Foreground="White" Margin="0,5,0,5">
3434
<muxc:NavigationViewItem.Icon>
3535
<FontIcon Glyph="&#xe109;"/>
3636
</muxc:NavigationViewItem.Icon>
3737
</muxc:NavigationViewItem>
3838

39-
<muxc:NavigationViewItem Content="Notes" Tag="NotesPage" Foreground="White" Margin="0,5,0,5">
39+
<muxc:NavigationViewItem x:Name="NotesPageNavItem" Content="Notes" Tag="NotesPage" Foreground="White" Margin="0,5,0,5">
4040
<muxc:NavigationViewItem.Icon>
4141
<FontIcon Glyph="&#xe8a9;"/>
4242
</muxc:NavigationViewItem.Icon>
4343
</muxc:NavigationViewItem>
4444

45-
<muxc:NavigationViewItem Content="ToDo List" Tag="ToDoListPage" Foreground="White" Margin="0,5,0,5">
45+
<muxc:NavigationViewItem x:Name="ToDoListPageNavItem" Content="ToDo List" Tag="ToDoListPage" Foreground="White" Margin="0,5,0,5">
4646
<muxc:NavigationViewItem.Icon>
4747
<FontIcon Glyph="&#xe9d5;"/>
4848
</muxc:NavigationViewItem.Icon>

windows/ReactNativeNotes/NativeModules/DatabaseHandler.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ namespace winrt::ReactNativeNotes::implementation
8989
void SetLanguageValue( const int&& value ) noexcept
9090
{
9191
settings->Language( (LanguageValue)value );
92+
LanguageChanged( value );
9293
}
9394

9495
REACT_METHOD( GetThemeValue, L"getThemeValue" );
@@ -101,8 +102,15 @@ namespace winrt::ReactNativeNotes::implementation
101102
void SetThemeValue( const int&& value ) noexcept
102103
{
103104
settings->Theme( (ThemeValue)value );
105+
ThemeChanged( value );
104106
}
105107

108+
REACT_EVENT( ThemeChanged );
109+
std::function<void( unsigned int )> ThemeChanged;
110+
111+
REACT_EVENT( LanguageChanged );
112+
std::function<void( unsigned int )> LanguageChanged;
113+
106114
private:
107115
std::unique_ptr<Repository> data;
108116

0 commit comments

Comments
 (0)