Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Button component #125

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix color props
  • Loading branch information
hayanisaid committed Jul 22, 2022
commit 0faeb16cb4e0501356d97712514c05465d7608a5
1 change: 1 addition & 0 deletions packages/app/src/Clock.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class Clock extends React.Component {
<Text style={styles.time}>
{this.state.time}
</Text>

{/*<Text style={styles.time}>
{this.state.time}
</Text>
Expand Down
19 changes: 7 additions & 12 deletions packages/app/src/Sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ const styles = StyleSheet.create({
lineHeight: 40,
backgroundColor: 'orange',
},
buttonContainer:{
bottom:0,
position:"absolute"

}

});

class Item extends React.Component {
Expand Down Expand Up @@ -64,20 +60,19 @@ class Sidebar extends Component {
return (
<View style={styles.sidebar}>
{/*<View style={styles.container}>*/}
<Button
color={"#000"}
title="Click Me 🚀"
onClick = {()=>{alert('hi')}}
/>
<FocusableItem
focusKey="sidebar-item-1"
text="Rio de Janeiro"
idx={120}
/>
<FocusableItem focusKey="sidebar-item-2" text="Kyoto" idx={160} />
<FocusableItem focusKey="sidebar-item-3" text="Stockholm" idx={200} />
<View style={styles.buttonContainer}>
<Button
color="#2196F3''"
title="Navigate"
onClick = {()=>{}}
/>
</View>


{/*</View>*/}
</View>
Expand Down
35 changes: 23 additions & 12 deletions packages/react-ape/renderer/elements/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import {ButtonDefaults} from '../constants';
import {trackMousePosition,isMouseInside} from '../utils'
import type {CanvasComponentContext} from '../types'

//TODO adjust Opacity when focus, Blur

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a ticket for this TODO?

type PressEvent = {||};
type ButtonProps = {|
Expand Down Expand Up @@ -67,18 +68,21 @@ type ButtonProps = {|
|};

function renderButton(props: ButtonProps, apeContext:CanvasComponentContext, parentLayout) {
const {spatialGeometry } = parentLayout;
const {ctx} = apeContext;

// If is relative and x and y haven't be processed, don't render
if (!spatialGeometry) return null;
// start drawing the canvas
console.log('[PROPS]',props)
const {title, color} = props;
if(!title){
throw Error("Title required!")
}
const borderRadius = ButtonDefaults.containerStyle.borderRadius;
const backgroundColor = ButtonDefaults.containerStyle.backgroundColor;
let x = spatialGeometry.x || 0;
let y = spatialGeometry.y || 0;
let width = x + y * title.length /3;
let x = 40;
let y = 300;
const textWidth = ctx.measureText(title).width;
let width = textWidth * 1.5;
let height = ButtonDefaults.containerStyle.height;
let globalStyle = {
width: width,
Expand All @@ -91,20 +95,19 @@ function renderButton(props: ButtonProps, apeContext:CanvasComponentContext, par
};
const resetStyle = newStyle => {
globalStyle = {...globalStyle, newStyle};
console.log('style)))))', globalStyle);

};
const redrawButton = ctx => {
// TODO reset Style on focus
let newStyle = {
lineWidth: 2,
borderColor: '#ccc',
};
//let prevStyle = globalStyle
resetStyle(newStyle);
};

ctx.beginPath();
ctx.fillStyle = backgroundColor;
ctx.fillStyle = color || ButtonDefaults.containerStyle.backgroundColor
ctx.moveTo(x, y);
/**
* Top Right Radius
Expand Down Expand Up @@ -137,10 +140,16 @@ function renderButton(props: ButtonProps, apeContext:CanvasComponentContext, par
ctx.strokeStyle = globalStyle.borderColor;
ctx.stroke();
ctx.fillStyle = ButtonDefaults.textStyle.color;
ctx.font = `${ButtonDefaults.textStyle.fontSize} Helvetica`;
//ctx.fillText('Start', x+ width/2 , y + height / 2);
ctx.textAlign = 'center';
ctx.fillText(title, x + width / 2, y + height / 2);

//set the fontSize
const fontArgs = ctx.font.split(' ');
const newSize =` ${ButtonDefaults.textStyle.fontSize}px`;
ctx.font = newSize + ' ' + fontArgs[fontArgs.length - 1];

// ctx.textAlign = 'center';

// ctx.fillText(title, 400 / 2, y + height / 2,textWidth);
ctx.fillText(title , (x + textWidth /2.5), y + height /2);
ctx.closePath();

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

}



export default function createButtonInstance(props: ButtonProps): mixed {
return {
type: 'Button',
Expand Down