|
7 | 7 |
|
8 | 8 | import {ButtonDefaults} from '../constants'; |
9 | 9 | import {trackMousePosition,isMouseInside} from '../utils' |
| 10 | +import type {CanvasComponentContext} from '../types' |
10 | 11 | //TODO adjust Opacity when focus, Blur |
11 | 12 | type PressEvent = {||}; |
12 | 13 | type ButtonProps = {| |
@@ -65,8 +66,8 @@ type ButtonProps = {| |
65 | 66 | testID?: ?string, |
66 | 67 | |}; |
67 | 68 |
|
68 | | -function renderButton(props: ButtonProps, apeContext, parentLayout) { |
69 | | - const {spatialGeometry = {x: 0, y: 0}} = parentLayout; |
| 69 | +function renderButton(props: ButtonProps, apeContext:CanvasComponentContext, parentLayout) { |
| 70 | + const {spatialGeometry } = parentLayout; |
70 | 71 | const {ctx} = apeContext; |
71 | 72 |
|
72 | 73 | // If is relative and x and y haven't be processed, don't render |
@@ -160,11 +161,22 @@ function renderButton(props: ButtonProps, apeContext, parentLayout) { |
160 | 161 |
|
161 | 162 |
|
162 | 163 |
|
| 164 | + |
| 165 | +// TODO: |
| 166 | +/** |
| 167 | + * We need to remove addEventListeners from the renderButton |
| 168 | + * function because this function runs for each state/prop update. |
| 169 | + * It will keep creating/refreshing listeners for every render. |
| 170 | +
|
| 171 | +We can keep this way, if we run this addEventListener |
| 172 | +once by checking if the listener already exist. |
| 173 | +Note onClick will need to share scope with this function to work properly. |
| 174 | + */ |
163 | 175 | ctx.canvas.addEventListener('click', onClick, false); |
164 | 176 | ctx.canvas.addEventListener('focus', redrawButton); |
165 | 177 | ctx.canvas.addEventListener('blur', redrawButton); |
166 | 178 |
|
167 | | - // events |
| 179 | + |
168 | 180 | } |
169 | 181 |
|
170 | 182 | export default function createButtonInstance(props: ButtonProps): mixed { |
|
0 commit comments