66 */
77
88import { ButtonDefaults } from '../constants' ;
9- import { trackMousePosition , isMouseInside } from '../utils'
10- import type { CanvasComponentContext } from '../types'
9+ import { trackMousePosition , isMouseInside } from '../utils' ;
10+ import type { CanvasComponentContext } from '../types' ;
1111
1212//TODO adjust Opacity when focus, Blur
1313type PressEvent = { || } ;
1414type ButtonProps = { |
1515 title : string ,
1616 onPress : ( event ? : PressEvent ) => mixed ,
1717 onClick : ( event ?: SyntheticMouseEvent < HTMLButtonElement > ) => mixed ,
18+ //handleOnClick:(event?:SyntheticMouseEvent<HTMLButtonElement>)=>mixed,
1819 touchSoundDisabled ?: ?boolean ,
1920 color ?: ?string ,
2021 /**
@@ -60,54 +61,58 @@ type ButtonProps = {|
6061 * If true, disable all interactions for this component.
6162 */
6263 disabled ?: ?boolean ,
63-
64+ getDimension ?: ( ) => mixed ,
6465 /**
6566 * Used to locate this view in end-to-end tests.
6667 */
6768 testID ?: ?string ,
6869| } ;
6970
70- function renderButton ( props : ButtonProps , apeContext :CanvasComponentContext , parentLayout ) {
71+ function renderButton (
72+ props : ButtonProps ,
73+ apeContext : CanvasComponentContext ,
74+ parentLayout
75+ ) {
7176 const { ctx} = apeContext ;
7277
7378 // If is relative and x and y haven't be processed, don't render
7479 // start drawing the canvas
75- console . log ( '[PROPS]' , props )
80+ console . log ( '[PROPS]' , props ) ;
7681 const { title, color} = props ;
77- if ( ! title ) {
78- throw Error ( " Title required!" )
82+ if ( ! title ) {
83+ throw Error ( ' Title required!' ) ;
7984 }
8085 const borderRadius = ButtonDefaults . containerStyle . borderRadius ;
8186 const backgroundColor = ButtonDefaults . containerStyle . backgroundColor ;
8287 let x = 40 ;
8388 let y = 300 ;
89+
8490 const textWidth = ctx . measureText ( title ) . width ;
85- let width = textWidth * 1.5 ;
91+ let width = textWidth * 1.5 ;
8692 let height = ButtonDefaults . containerStyle . height ;
8793 let globalStyle = {
8894 width : width ,
8995 height : height ,
9096 color : color ,
9197 borderRadius : borderRadius ,
92- backgroundColor :color ,
98+ backgroundColor : color ,
9399 lineWidth : 0 ,
94100 borderColor : 'transparent' ,
95101 } ;
96102 const resetStyle = newStyle => {
97103 globalStyle = { ...globalStyle , newStyle} ;
98-
99- } ;
100- const redrawButton = ctx => {
101- // TODO reset Style on focus
102- let newStyle = {
103- lineWidth : 2 ,
104- borderColor : '#ccc' ,
105- } ;
106- resetStyle ( newStyle ) ;
107104 } ;
105+ // const redrawButton = ctx => {
106+ // // TODO reset Style on focus
107+ // let newStyle = {
108+ // lineWidth: 2,
109+ // borderColor: '#ccc',
110+ // };
111+ // resetStyle(newStyle);
112+ // };
108113
109114 ctx . beginPath ( ) ;
110- ctx . fillStyle = color || ButtonDefaults . containerStyle . backgroundColor
115+ ctx . fillStyle = color || ButtonDefaults . containerStyle . backgroundColor ;
111116 ctx . moveTo ( x , y ) ;
112117 /**
113118* Top Right Radius
@@ -139,40 +144,40 @@ function renderButton(props: ButtonProps, apeContext:CanvasComponentContext, par
139144 ctx . lineWidth = globalStyle . lineWidth ;
140145 ctx . strokeStyle = globalStyle . borderColor ;
141146 ctx . stroke ( ) ;
142- ctx . fillStyle = ButtonDefaults . textStyle . color ;
147+ ctx . fillStyle = ButtonDefaults . textStyle . color ;
143148
144149 //set the fontSize
145- const fontArgs = ctx . font . split ( ' ' ) ;
146- const newSize = ` ${ ButtonDefaults . textStyle . fontSize } px` ;
150+ const fontArgs = ctx . font . split ( ' ' ) ;
151+ const newSize = ` ${ ButtonDefaults . textStyle . fontSize } px` ;
147152 ctx . font = newSize + ' ' + fontArgs [ fontArgs . length - 1 ] ;
148153
149- // ctx.textAlign = 'center';
154+ // ctx.textAlign = 'center';
150155
151- // ctx.fillText(title, 400 / 2, y + height / 2,textWidth);
152- ctx . fillText ( title , ( x + textWidth / 2.5 ) , y + height / 2 ) ;
156+ // ctx.fillText(title, 400 / 2, y + height / 2,textWidth);
157+ ctx . fillText ( title , x + textWidth / 2.5 , y + height / 2 ) ;
153158 ctx . closePath ( ) ;
154-
155- const onClick = ( event : SyntheticMouseEvent < HTMLButtonElement > ) => {
156- const rect = {
157- x ,
158- y ,
159- height ,
160- width ,
161- } ;
162- const mousePosition = trackMousePosition ( ctx . canvas , event ) ;
163- if ( isMouseInside ( mousePosition , rect ) ) {
164- redrawButton ( ctx ) ;
165- if ( props . onClick && typeof props . onClick === 'function' ) {
166- props . onClick ( event ) ;
167- }
168- }
169- } ;
170-
171-
172-
173-
174- // TODO:
175- /**
159+ // if(props.handleOnClick){
160+ // onClick()
161+ // }
162+
163+ // const onClick = (event: SyntheticMouseEvent<HTMLButtonElement>) => {
164+ // const rect = {
165+ // x ,
166+ // y,
167+ // height,
168+ // width,
169+ // } ;
170+ // const mousePosition = trackMousePosition(ctx.canvas, event);
171+ // if (isMouseInside(mousePosition, rect)) {
172+ // redrawButton(ctx);
173+ // if (props.onClick && typeof props.onClick === 'function') {
174+ // props.onClick(event) ;
175+ // }
176+ // }
177+ // };
178+
179+ // TODO:
180+ /**
176181 * We need to remove addEventListeners from the renderButton
177182 * function because this function runs for each state/prop update.
178183 * It will keep creating/refreshing listeners for every render.
@@ -181,15 +186,11 @@ We can keep this way, if we run this addEventListener
181186once by checking if the listener already exist.
182187Note onClick will need to share scope with this function to work properly.
183188 */
184- ctx . canvas . addEventListener ( 'click' , onClick , false ) ;
185- ctx . canvas . addEventListener ( 'focus' , redrawButton ) ;
186- ctx . canvas . addEventListener ( 'blur' , redrawButton ) ;
187-
188-
189+ // ctx.canvas.addEventListener('click', onClick, false);
190+ // ctx.canvas.addEventListener('focus', redrawButton);
191+ // ctx.canvas.addEventListener('blur', redrawButton);
189192}
190193
191-
192-
193194export default function createButtonInstance ( props : ButtonProps ) : mixed {
194195 return {
195196 type : 'Button' ,
0 commit comments