77
88import { ButtonDefaults } from '../constants' ;
99
10+ //TODO adjust Opacity when focus, Blur
11+ type PressEvent = { || } ;
1012type ButtonProps = { |
1113 title : string ,
12- onPress : ( event ? : any ) => mixed ,
14+ onPress : ( event ? : PressEvent ) => mixed ,
1315 touchSoundDisabled ?: ?boolean ,
1416 color ?: ?string ,
1517 /**
@@ -62,34 +64,34 @@ type ButtonProps = {|
6264 testID ?: ?string ,
6365| } ;
6466
65- function renderButton ( props , apeContext , parentLayout ) {
66- const { spatialGeometry = { } , relativeIndex} = parentLayout ;
67+ function renderButton ( props : ButtonProps , apeContext , parentLayout ) {
68+ const { spatialGeometry = { x : 0 , y : 0 } , relativeIndex} = parentLayout ;
6769 const { ctx} = apeContext ;
6870 // If is relative and x and y haven't be processed, don't render
6971 if ( ! spatialGeometry ) return null ;
7072 // start drawing the canvas
7173 const { title, color} = props ;
7274 const borderRadius = ButtonDefaults . containerStyle . borderRadius ;
7375 const backgroundColor = ButtonDefaults . containerStyle . backgroundColor ;
74- let x = spatialGeometry . x || 20 ;
75- let y = spatialGeometry . y || 40 ;
76- const width = x + y ;
77- const height = ButtonDefaults . containerStyle . height ;
76+ let x = spatialGeometry . x || 0 ;
77+ let y = spatialGeometry . y || 0 ;
78+ let width = x + y ;
79+ let height = ButtonDefaults . containerStyle . height ;
80+ // if(parentLayout && parentLayout.style){
81+ // width = parentLayout.style.width
82+ // height = parentLayout.style.height
83+ // }
7884 ctx . beginPath ( ) ;
79- //ctx.lineWidth = borderWidth
8085 ctx . fillStyle = backgroundColor ;
81- //ctx.strokeStyle = borderColor
82- //ctx.rect(x,y,borderRadius,width,height,antiClockWise)
83- //ctx.rect(x,y,width,height)
8486 ctx . moveTo ( x , y ) ;
8587 /**
86- * Top Right Radius
87- */
88+ * Top Right Radius
89+ */
8890 ctx . lineTo ( x + width - borderRadius , y ) ;
8991 ctx . quadraticCurveTo ( x + width , y , x + width , y + borderRadius ) ;
9092 /**
91- * Bottom right Radius
92- */
93+ * Bottom right Radius
94+ */
9395
9496 ctx . lineTo ( x + width , y + height - borderRadius ) ;
9597 ctx . quadraticCurveTo (
@@ -100,8 +102,8 @@ function renderButton(props, apeContext, parentLayout) {
100102 ) ;
101103
102104 /**
103- * Bottom Left Radius
104- */
105+ * Bottom Left Radius
106+ */
105107 ctx . lineTo ( x + borderRadius , y + height ) ;
106108 ctx . quadraticCurveTo ( x , y + height , x , y + height - borderRadius ) ;
107109 /** Top left Radius */
@@ -119,7 +121,7 @@ function renderButton(props, apeContext, parentLayout) {
119121 ctx . closePath ( ) ;
120122}
121123
122- export default function createButtonInstance ( props : Props ) : mixed {
124+ export default function createButtonInstance ( props : ButtonProps ) : mixed {
123125 return {
124126 type : 'Button' ,
125127 render : renderButton . bind ( this , props ) ,
0 commit comments