Skip to content

Commit d3ca898

Browse files
committed
rebase
1 parent 85cd94c commit d3ca898

File tree

3 files changed

+38
-20
lines changed

3 files changed

+38
-20
lines changed

packages/app/src/Sidebar.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
View,
55
Dimensions,
66
StyleSheet,
7+
Button,
78
registerComponent,
89
withFocus,
910
} from '../../react-ape/reactApeEntry';
@@ -27,6 +28,11 @@ const styles = StyleSheet.create({
2728
lineHeight: 40,
2829
backgroundColor: 'orange',
2930
},
31+
buttonContainer:{
32+
bottom:0,
33+
position:"absolute"
34+
35+
}
3036
});
3137

3238
class Item extends React.Component {
@@ -65,6 +71,14 @@ class Sidebar extends Component {
6571
/>
6672
<FocusableItem focusKey="sidebar-item-2" text="Kyoto" idx={160} />
6773
<FocusableItem focusKey="sidebar-item-3" text="Stockholm" idx={200} />
74+
<View style={styles.buttonContainer}>
75+
<Button
76+
color="blue'"
77+
title="Navigate"
78+
onClick = {()=>{}}
79+
/>
80+
</View>
81+
6882
{/*</View>*/}
6983
</View>
7084
);

packages/react-ape/renderer/elements/Button.js

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import {ButtonDefaults} from '../constants';
9-
9+
import {trackMousePosition,isMouseInside} from '../utils'
1010
//TODO adjust Opacity when focus, Blur
1111
type PressEvent = {||};
1212
type ButtonProps = {|
@@ -66,8 +66,6 @@ type ButtonProps = {|
6666
|};
6767

6868
function renderButton(props: ButtonProps, apeContext, parentLayout) {
69-
//
70-
console.log('[RENDER]');
7169
const {spatialGeometry = {x: 0, y: 0}} = parentLayout;
7270
const {ctx} = apeContext;
7371

@@ -79,7 +77,7 @@ function renderButton(props: ButtonProps, apeContext, parentLayout) {
7977
const backgroundColor = ButtonDefaults.containerStyle.backgroundColor;
8078
let x = spatialGeometry.x || 0;
8179
let y = spatialGeometry.y || 0;
82-
let width = x + y;
80+
let width = x + y * title.length /3;
8381
let height = ButtonDefaults.containerStyle.height;
8482
let globalStyle = {
8583
width: width,
@@ -105,7 +103,7 @@ function renderButton(props: ButtonProps, apeContext, parentLayout) {
105103
};
106104

107105
ctx.beginPath();
108-
ctx.fillStyle = color;
106+
ctx.fillStyle = backgroundColor;
109107
ctx.moveTo(x, y);
110108
/**
111109
* Top Right Radius
@@ -152,27 +150,15 @@ function renderButton(props: ButtonProps, apeContext, parentLayout) {
152150
width,
153151
};
154152
const mousePosition = trackMousePosition(ctx.canvas, event);
155-
if (isInside(mousePosition, rect)) {
153+
if (isMouseInside(mousePosition, rect)) {
156154
redrawButton(ctx);
157155
if (props.onClick && typeof props.onClick === 'function') {
158156
props.onClick(event);
159157
}
160158
}
161159
};
162-
function trackMousePosition(canvas, event) {
163-
return {
164-
x: event.clientX - canvas.offsetLeft,
165-
y: event.clientY - canvas.offsetTop,
166-
};
167-
}
168-
const isInside = (pos, rect) => {
169-
return (
170-
pos.x > rect.x &&
171-
pos.x < rect.x + rect.width &&
172-
pos.y < rect.y + rect.height &&
173-
pos.y > rect.y
174-
);
175-
};
160+
161+
176162

177163
ctx.canvas.addEventListener('click', onClick, false);
178164
ctx.canvas.addEventListener('focus', redrawButton);

packages/react-ape/renderer/utils.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,21 @@
66
export function unsafeCreateUniqueId(): string {
77
return (Math.random() * 10e18 + Date.now()).toString(36);
88
}
9+
type MouseEventType={|
10+
x:number,
11+
y:number
12+
|}
13+
export function trackMousePosition(canvas, event):MouseEventType {
14+
return {
15+
x: event.clientX - canvas.offsetLeft,
16+
y: event.clientY - canvas.offsetTop,
17+
};
18+
}
19+
export const isMouseInside = (pos, rect):Boolean => {
20+
return (
21+
pos.x > rect.x &&
22+
pos.x < rect.x + rect.width &&
23+
pos.y < rect.y + rect.height &&
24+
pos.y > rect.y
25+
);
26+
};

0 commit comments

Comments
 (0)