Skip to content

Commit 0faeb16

Browse files
committed
Fix color props
1 parent 5691c82 commit 0faeb16

File tree

3 files changed

+31
-24
lines changed

3 files changed

+31
-24
lines changed

packages/app/src/Clock.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class Clock extends React.Component {
5151
<Text style={styles.time}>
5252
{this.state.time}
5353
</Text>
54+
5455
{/*<Text style={styles.time}>
5556
{this.state.time}
5657
</Text>

packages/app/src/Sidebar.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@ const styles = StyleSheet.create({
2828
lineHeight: 40,
2929
backgroundColor: 'orange',
3030
},
31-
buttonContainer:{
32-
bottom:0,
33-
position:"absolute"
34-
35-
}
31+
3632
});
3733

3834
class Item extends React.Component {
@@ -64,20 +60,19 @@ class Sidebar extends Component {
6460
return (
6561
<View style={styles.sidebar}>
6662
{/*<View style={styles.container}>*/}
63+
<Button
64+
color={"#000"}
65+
title="Click Me 🚀"
66+
onClick = {()=>{alert('hi')}}
67+
/>
6768
<FocusableItem
6869
focusKey="sidebar-item-1"
6970
text="Rio de Janeiro"
7071
idx={120}
7172
/>
7273
<FocusableItem focusKey="sidebar-item-2" text="Kyoto" idx={160} />
7374
<FocusableItem focusKey="sidebar-item-3" text="Stockholm" idx={200} />
74-
<View style={styles.buttonContainer}>
75-
<Button
76-
color="#2196F3''"
77-
title="Navigate"
78-
onClick = {()=>{}}
79-
/>
80-
</View>
75+
8176

8277
{/*</View>*/}
8378
</View>

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

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import {ButtonDefaults} from '../constants';
99
import {trackMousePosition,isMouseInside} from '../utils'
1010
import type {CanvasComponentContext} from '../types'
11+
1112
//TODO adjust Opacity when focus, Blur
1213
type PressEvent = {||};
1314
type ButtonProps = {|
@@ -67,18 +68,21 @@ type ButtonProps = {|
6768
|};
6869

6970
function renderButton(props: ButtonProps, apeContext:CanvasComponentContext, parentLayout) {
70-
const {spatialGeometry } = parentLayout;
7171
const {ctx} = apeContext;
7272

7373
// If is relative and x and y haven't be processed, don't render
74-
if (!spatialGeometry) return null;
7574
// start drawing the canvas
75+
console.log('[PROPS]',props)
7676
const {title, color} = props;
77+
if(!title){
78+
throw Error("Title required!")
79+
}
7780
const borderRadius = ButtonDefaults.containerStyle.borderRadius;
7881
const backgroundColor = ButtonDefaults.containerStyle.backgroundColor;
79-
let x = spatialGeometry.x || 0;
80-
let y = spatialGeometry.y || 0;
81-
let width = x + y * title.length /3;
82+
let x = 40;
83+
let y = 300;
84+
const textWidth = ctx.measureText(title).width;
85+
let width = textWidth * 1.5;
8286
let height = ButtonDefaults.containerStyle.height;
8387
let globalStyle = {
8488
width: width,
@@ -91,20 +95,19 @@ function renderButton(props: ButtonProps, apeContext:CanvasComponentContext, par
9195
};
9296
const resetStyle = newStyle => {
9397
globalStyle = {...globalStyle, newStyle};
94-
console.log('style)))))', globalStyle);
98+
9599
};
96100
const redrawButton = ctx => {
97101
// TODO reset Style on focus
98102
let newStyle = {
99103
lineWidth: 2,
100104
borderColor: '#ccc',
101105
};
102-
//let prevStyle = globalStyle
103106
resetStyle(newStyle);
104107
};
105108

106109
ctx.beginPath();
107-
ctx.fillStyle = backgroundColor;
110+
ctx.fillStyle = color || ButtonDefaults.containerStyle.backgroundColor
108111
ctx.moveTo(x, y);
109112
/**
110113
* Top Right Radius
@@ -137,10 +140,16 @@ function renderButton(props: ButtonProps, apeContext:CanvasComponentContext, par
137140
ctx.strokeStyle = globalStyle.borderColor;
138141
ctx.stroke();
139142
ctx.fillStyle = ButtonDefaults.textStyle.color;
140-
ctx.font = `${ButtonDefaults.textStyle.fontSize} Helvetica`;
141-
//ctx.fillText('Start', x+ width/2 , y + height / 2);
142-
ctx.textAlign = 'center';
143-
ctx.fillText(title, x + width / 2, y + height / 2);
143+
144+
//set the fontSize
145+
const fontArgs = ctx.font.split(' ');
146+
const newSize =` ${ButtonDefaults.textStyle.fontSize}px`;
147+
ctx.font = newSize + ' ' + fontArgs[fontArgs.length - 1];
148+
149+
// ctx.textAlign = 'center';
150+
151+
// ctx.fillText(title, 400 / 2, y + height / 2,textWidth);
152+
ctx.fillText(title , (x + textWidth /2.5), y + height /2);
144153
ctx.closePath();
145154

146155
const onClick = (event: SyntheticMouseEvent<HTMLButtonElement>) => {
@@ -179,6 +188,8 @@ Note onClick will need to share scope with this function to work properly.
179188

180189
}
181190

191+
192+
182193
export default function createButtonInstance(props: ButtonProps): mixed {
183194
return {
184195
type: 'Button',

0 commit comments

Comments
 (0)