Skip to content

Commit e327de6

Browse files
committed
0.0.9-alpha.3 (fix ci)
1 parent 10575dc commit e327de6

File tree

12 files changed

+64
-75
lines changed

12 files changed

+64
-75
lines changed

packages/app/src/App.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
Dimensions,
77
StyleSheet,
88
registerComponent,
9-
withNavigation
9+
withNavigation,
1010
} from '../../react-ape/reactApeEntry';
1111

1212
// import Spinner from './Spinner';

packages/app/src/Sidebar.js

+14-21
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,21 @@ const styles = StyleSheet.create({
2525
// top: 100,
2626
borderRadius: 10,
2727
lineHeight: 40,
28-
backgroundColor: 'orange'
28+
backgroundColor: 'orange',
2929
},
3030
});
3131

3232
class Item extends React.Component {
3333
render() {
34-
const { focused, idx, text, setFocus } = this.props;
34+
const {focused, idx, text, setFocus} = this.props;
3535
console.log('focusableitem', setFocus, focused);
3636
return (
3737
<View style={{...styles.container, top: idx}}>
38-
<Text style={{
39-
color: focused ? '#331A00' : 'white',
40-
fontSize: 24
41-
}}>
38+
<Text
39+
style={{
40+
color: focused ? '#331A00' : 'white',
41+
fontSize: 24,
42+
}}>
4243
{text}
4344
</Text>
4445
</View>
@@ -57,21 +58,13 @@ class Sidebar extends Component {
5758
return (
5859
<View style={styles.sidebar}>
5960
{/*<View style={styles.container}>*/}
60-
<FocusableItem
61-
focusKey="sidebar-item-1"
62-
text="Rio de Janeiro"
63-
idx={120}
64-
/>
65-
<FocusableItem
66-
focusKey="sidebar-item-2"
67-
text="Kyoto"
68-
idx={160}
69-
/>
70-
<FocusableItem
71-
focusKey="sidebar-item-3"
72-
text="Stockholm"
73-
idx={200}
74-
/>
61+
<FocusableItem
62+
focusKey="sidebar-item-1"
63+
text="Rio de Janeiro"
64+
idx={120}
65+
/>
66+
<FocusableItem focusKey="sidebar-item-2" text="Kyoto" idx={160} />
67+
<FocusableItem focusKey="sidebar-item-3" text="Stockholm" idx={200} />
7568
{/*</View>*/}
7669
</View>
7770
);

packages/react-ape/__tests__/render-tests/__snapshots__/render-updates.js.snap

+4-4
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import React from 'react';
22

3-
export const FocusPathContext = React.createContext();
3+
export const FocusPathContext = React.createContext();

packages/react-ape/modules/Navigation/FocusSpatialMap.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
// const FocusSpatialMap = new Map();
33
const FocusSpatialMap = [];
44

5-
export default FocusSpatialMap
5+
export default FocusSpatialMap;

packages/react-ape/modules/Navigation/__tests__/withFocusable-test.js

-11
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import withNavigation from '../withNavigation';
2+
3+
describe('withNavigation', () => {
4+
test('should not return null', () => {
5+
expect(typeof withNavigation).toEqual('function');
6+
});
7+
});

packages/react-ape/modules/Navigation/withFocus.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
*/
44

55
import * as React from 'react';
6-
import { getComponentDisplayName } from '../utils';
7-
import { FocusPathContext } from './FocusPathContext';
6+
import {getComponentDisplayName} from '../utils';
7+
import {FocusPathContext} from './FocusPathContext';
88

99
type RequiredProps = {
10-
focusKey: string
10+
focusKey: string,
1111
};
1212

1313
// See why we do `| void`
1414
// https://flow.org/en/docs/react/hoc/#toc-injecting-props-with-a-higher-order-component
1515
type InjectedProps = {
16-
focused: boolean | void
16+
focused: boolean | void,
1717
};
1818

1919
/**
@@ -39,8 +39,8 @@ function withFocus<Props: RequiredProps>(
3939
renderWithFocusPath = focusContext => {
4040
// TODO: I need to listen to a global and observable focusPath that will
4141
// define if this component should be focused or not (the value of focused)
42-
const { setFocus, currentFocusPath } = focusContext;
43-
const { focusKey } = this.props;
42+
const {setFocus, currentFocusPath} = focusContext;
43+
const {focusKey} = this.props;
4444
// const focusPath = `${rootFocusPath}/${focusKey}`;
4545

4646
FocusSpatialMap.push(focusKey);
@@ -67,4 +67,4 @@ function withFocus<Props: RequiredProps>(
6767
};
6868
}
6969

70-
export default withFocus;
70+
export default withFocus;

packages/react-ape/modules/Navigation/withNavigation.js

+25-24
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,21 @@
33
*/
44

55
import * as React from 'react';
6-
import { getComponentDisplayName } from '../utils';
7-
import { unsafeCreateUniqueId } from '../../renderer/utils';
8-
import { FocusPathContext } from './FocusPathContext';
6+
import {getComponentDisplayName} from '../utils';
7+
import {unsafeCreateUniqueId} from '../../renderer/utils';
8+
import {FocusPathContext} from './FocusPathContext';
99
import FocusSpatialMap from './FocusSpatialMap';
1010

1111
type RequiredProps = {};
1212

1313
// See why we do `| void`
1414
// https://flow.org/en/docs/react/hoc/#toc-injecting-props-with-a-higher-order-component
1515
type InjectedProps = {
16-
focusPath: string | void
16+
focusPath: string | void,
17+
};
18+
19+
type State = {
20+
currentFocusPath: ?string,
1721
};
1822

1923
/**
@@ -24,13 +28,14 @@ type InjectedProps = {
2428
function withNavigation<Props: RequiredProps>(
2529
WrappedComponent: React.ComponentType<Props>
2630
): React.ComponentType<$Diff<Props, InjectedProps>> {
27-
return class extends React.Component<Props> {
31+
return class extends React.Component<Props, State> {
2832
static WrappedComponent = WrappedComponent;
2933
static displayName = `withNavigation(${getComponentDisplayName(
3034
WrappedComponent
3135
)})`;
3236

3337
rootFocusPath: string;
38+
focusPathList: mixed;
3439

3540
constructor() {
3641
super(...arguments);
@@ -39,56 +44,52 @@ function withNavigation<Props: RequiredProps>(
3944

4045
this.focusPathList = [];
4146
this.state = {
42-
currentFocusPath: false
47+
currentFocusPath: null,
4348
};
44-
window.addEventListener('keydown', (e) => this.handleKeyDown(e));
45-
}
46-
47-
setFocus = (currentFocusPath) => {
48-
this.setState({ currentFocusPath });
49+
window.addEventListener('keydown', e => this.handleKeyDown(e));
4950
}
5051

51-
setFocusNext() {
52+
setFocus = currentFocusPath => {
53+
this.setState({currentFocusPath});
54+
};
5255

53-
}
56+
setFocusNext() {}
5457

55-
handleKeyDown = (e) => {
56-
const { currentFocusPath } = this.state;
58+
handleKeyDown = e => {
59+
const {currentFocusPath} = this.state;
5760
// arrow up/down button should select next/previous list element
5861
if (e.keyCode === 38) {
5962
// console.log(FocusSpatialMap.indexOf(currentFocusPath))
6063
// this.setState( prevState => ({
61-
6264
// }))
6365
} else if (e.keyCode === 40) {
6466
// console.log(FocusSpatialMap.indexOf(currentFocusPath))
6567
const idx = FocusSpatialMap.indexOf(currentFocusPath) + 1;
6668
const next = idx + 1;
6769
const nextFocusPath = FocusSpatialMap[next];
6870
this.setState({
69-
currentFocusPath: nextFocusPath
71+
currentFocusPath: nextFocusPath,
7072
});
7173
// this.setState( prevState => ({
7274
// cursor: prevState.cursor + 1
7375
// }))
7476
}
75-
}
77+
};
7678

7779
render() {
78-
const { currentFocusPath } = this.state;
80+
const {currentFocusPath} = this.state;
7981
return (
80-
<FocusPathContext.Provider
82+
<FocusPathContext.Provider
8183
value={{
8284
// rootFocusPath: this.rootFocusPath,
8385
currentFocusPath: currentFocusPath,
84-
setFocus: this.setFocus
85-
}}
86-
>
86+
setFocus: this.setFocus,
87+
}}>
8788
<WrappedComponent {...this.props} />
8889
</FocusPathContext.Provider>
8990
);
9091
}
9192
};
9293
}
9394

94-
export default withNavigation;
95+
export default withNavigation;

packages/react-ape/modules/utils.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
21
/**
32
* @flow
43
*/
54

6-
import type { ComponentType } from 'react';
5+
import type {ComponentType} from 'react';
76

87
export function getComponentDisplayName<T: {}>(Comp: ComponentType<T>): string {
98
return Comp.displayName || Comp.name || 'Component';

packages/react-ape/renderer/reactApeComponentTree.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
*/
88

9-
import { unsafeCreateUniqueId } from './utils';
9+
import {unsafeCreateUniqueId} from './utils';
1010

1111
const randomKey = unsafeCreateUniqueId();
1212
const internalInstanceKey = '__reactInternalInstance$' + randomKey;

packages/react-ape/renderer/utils.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
* this function.
55
*/
66
export function unsafeCreateUniqueId(): string {
7-
return ((Math.random() * 10e18) + Date.now()).toString(36);
8-
}
7+
return (Math.random() * 10e18 + Date.now()).toString(36);
8+
}

0 commit comments

Comments
 (0)