Skip to content

Commit fbac3b9

Browse files
committed
Merge branch 'master' of https://github.com/gravitypersists/react-countdown-clock into gravitypersists-master
2 parents 6437421 + a0de8fd commit fbac3b9

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ npm install react-countdown-clock
2121
color="#000"
2222
alpha={0.9}
2323
size={300}
24+
scale={window.devicePixelRatio}
2425
onComplete={myCallback} />
2526
```
2627

@@ -40,6 +41,7 @@ npm install react-countdown-clock
4041
| onComplete | func | | Callback when time completes |
4142
| paused | boolean | false | Pause countdown of the timer |
4243
| pausedText | string | | Text to display when paused, defaults to the current time |
44+
| scale | float | 1 | Scale of canvas, set this to `window.devicePixelRatio` |
4345

4446
## Bugs & Contributions
4547

build/react-countdown-clock.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coffee/react-countdown-clock.coffee

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ ReactCountdownClock = CreateReactClass
6868
@_timer.textBaseline = 'middle'
6969
if @props.onClick?
7070
@refs.component.addEventListener 'click', @props.onClick
71+
if @props.scale?
72+
@_background.scale(@props.scale, @props.scale)
73+
@_timer.scale(@props.scale, @props.scale)
7174

7275
_startTimer: ->
7376
# Give it a moment to collect it's thoughts for smoother render
@@ -174,9 +177,13 @@ ReactCountdownClock = CreateReactClass
174177
@_timer.fill()
175178

176179
render: ->
177-
<div ref='component' className="react-countdown-clock" style={width: @props.size, height: @props.size}>
178-
<canvas ref='background' style={ position: 'absolute' } width={@props.size} height={@props.size}></canvas>
179-
<canvas ref='timer' style={ position: 'absolute' } width={@props.size} height={@props.size}></canvas>
180+
width = @props.size * @props.scale
181+
height = @props.size * @props.scale
182+
style = { position: 'absolute', width: width / 2, height: height / 2 }
183+
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>
180187
</div>
181188

182189
ReactCountdownClock.propTypes =
@@ -193,6 +200,7 @@ ReactCountdownClock.propTypes =
193200
showMilliseconds: PropTypes.bool
194201
paused: PropTypes.bool
195202
pausedText: PropTypes.string
203+
scale: PropTypes.number
196204

197205
ReactCountdownClock.defaultProps =
198206
seconds: 60
@@ -204,5 +212,6 @@ ReactCountdownClock.defaultProps =
204212
font: 'Arial'
205213
showMilliseconds: true
206214
paused: false
215+
scale: 1
207216

208217
module.exports = ReactCountdownClock

index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@
6969
alpha: 0.9,
7070
onComplete: this.handleOnComplete,
7171
onClick: this.handleOnClick,
72-
fontSize: this.state.fontSize
72+
fontSize: this.state.fontSize,
73+
scale: window.devicePixelRatio
7374
})
7475
)
7576
}

0 commit comments

Comments
 (0)