-
-
Notifications
You must be signed in to change notification settings - Fork 48
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
base: main
Are you sure you want to change the base?
Button component #125
Conversation
hayanisaid
commented
Jun 22, 2022
- Created Button component
- Add onClick event
); | ||
}; | ||
|
||
ctx.canvas.addEventListener('click', onClick, false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to remove addEventListeners from the renderButton function because this function runs for each state/prop update. It will keep creating/refreshing listeners for every render.
We can keep this way, if we run this addEventListener once by checking if the listener already exist. Note onClick will need to share scope with this function to work properly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Working on this!
Question! how to connect the component to the spatialGeometry
context?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this property will need to be coming from parent View instead of itself. Btw, if you want to join the discord to talk, there's a link here https://medium.com/@raphamorim/bet-on-canvas-for-a-high-performant-tv-application-with-react-ape-cdf8c0b77c21
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Invalid Discord link invite!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops, try this link https://discord.gg/njHHfRzJ42
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job! Left some comments but it looks good for initial version
@hayanisaid other two points would be good to have in this PR:
|
@raphamorim Thanks for the feedback, working on applying those changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job
9cc4a45
to
7b161c6
Compare
import React from "react"; | ||
import { Button, View, render } from "react-ape"; | ||
|
||
class ImageExample extends React.Component { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be ButtonExample
?
title: string, | ||
onPress: (event?: PressEvent) => mixed, | ||
onClick: (event?: SyntheticMouseEvent<HTMLButtonElement>) => mixed, | ||
//handleOnClick:(event?:SyntheticMouseEvent<HTMLButtonElement>)=>mixed, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this dead code?
import {trackMousePosition, isMouseInside} from '../utils'; | ||
import type {CanvasComponentContext} from '../types'; | ||
|
||
//TODO adjust Opacity when focus, Blur |
There was a problem hiding this comment.
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?
|
||
// If is relative and x and y haven't be processed, don't render | ||
// start drawing the canvas | ||
console.log('[PROPS]', props); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you want logging here?
const resetStyle = newStyle => { | ||
globalStyle = {...globalStyle, newStyle}; | ||
}; | ||
// const redrawButton = ctx => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this be removed if commented out?
const newSize = `${ButtonDefaults.textStyle.fontSize}px`; | ||
ctx.font = newSize + ' ' + fontArgs[fontArgs.length - 1]; | ||
|
||
// ctx.textAlign = 'center'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this be removed if commented out?
|
||
// ctx.textAlign = 'center'; | ||
|
||
// ctx.fillText(title, 400 / 2, y + height / 2,textWidth); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this be removed if commented out?
// ctx.fillText(title, 400 / 2, y + height / 2,textWidth); | ||
ctx.fillText(title, x + textWidth / 2.5, y + height / 2); | ||
ctx.closePath(); | ||
// if(props.handleOnClick){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this be removed if commented out? This stretches all the way down to line 192
* Handling click button event | ||
* @param {*} event | ||
*/ | ||
// const onClick = (event: SyntheticMouseEvent<HTMLButtonElement>) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this be removed if commented out?