@@ -9,10 +9,12 @@ ReactCountdownClock = CreateReactClass
99 _content : null
1010 _canvas : null
1111 _timeoutIds : []
12+ _scale : window .devicePixelRatio || 1
1213
1314 displayName : ' ReactCountdownClock'
1415
1516 componentDidUpdate : (props ) ->
17+ console .log @props
1618 if props .seconds != @props .seconds
1719 @_seconds = @props .seconds
1820 @ _setupTimer ()
@@ -62,19 +64,22 @@ ReactCountdownClock = CreateReactClass
6264 if tick > 1000 then 1000 else tick
6365
6466 _setupCanvases : ->
67+ return if @_background && @_timer
68+
6569 @_background = @refs .background .getContext ' 2d'
70+ @_background .scale @_scale , @_scale
71+
6672 @_timer = @refs .timer .getContext ' 2d'
6773 @_timer .textAlign = ' center'
6874 @_timer .textBaseline = ' middle'
75+ @_timer .scale @_scale , @_scale
76+
6977 if @props .onClick ?
7078 @refs .component .addEventListener ' click' , @props .onClick
71- if @props .scale ?
72- @_background .scale (@props .scale , @props .scale )
73- @_timer .scale (@props .scale , @props .scale )
7479
7580 _startTimer : ->
7681 # Give it a moment to collect it's thoughts for smoother render
77- @_timeoutIds .push (setTimeout ( => @ _tick () ), 200 )
82+ @_timeoutIds .push (setTimeout ( => @ _tick () ), 200 )
7883
7984 _pauseTimer : ->
8085 @ _stopTimer ()
@@ -177,13 +182,12 @@ ReactCountdownClock = CreateReactClass
177182 @_timer .fill ()
178183
179184 render : ->
180- width = @props .size * @props .scale
181- height = @props .size * @props .scale
182- style = { position : ' absolute' , width : width / 2 , height : height / 2 }
185+ canvasStyle = { position : ' absolute' , width : @props .size , height : @props .size }
186+ canvasProps = { style : canvasStyle, height : @props .size * @_scale , width : @props .size * @_scale }
183187
184- <div ref = ' component' className = " react-countdown-clock" style = {width : width , height : height }>
185- <canvas ref = ' background' style = {style} width = {width} height = {height }></canvas >
186- <canvas ref = ' timer' style = {style} width = {width} height = {height }></canvas >
188+ <div ref = ' component' className = " react-countdown-clock" style = {width : @props . size , height : @props . size }>
189+ <canvas ref = ' background' { ... canvasProps }></canvas >
190+ <canvas ref = ' timer' { ... canvasProps }></canvas >
187191 </div >
188192
189193ReactCountdownClock .propTypes =
@@ -200,7 +204,6 @@ ReactCountdownClock.propTypes =
200204 showMilliseconds : PropTypes .bool
201205 paused : PropTypes .bool
202206 pausedText : PropTypes .string
203- scale : PropTypes .number
204207
205208ReactCountdownClock .defaultProps =
206209 seconds : 60
@@ -212,6 +215,5 @@ ReactCountdownClock.defaultProps =
212215 font : ' Arial'
213216 showMilliseconds : true
214217 paused : false
215- scale : 1
216218
217219module .exports = ReactCountdownClock
0 commit comments