Skip to content

Commit

Permalink
ensure renderer and configuration are set on sampleLayer
Browse files Browse the repository at this point in the history
`didSet` doesn't get called in the initializer, so the sampleLayer wouldn't get the same info until it gets updated.
Using defer here (to call didSet) as opposed to calling the code in didSet directly just because I feel it looks cleaner ¯\_(ツ)_/¯

fixes #58
  • Loading branch information
dmrschmidt committed Mar 11, 2023
1 parent b3a955b commit f46cf06
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Sources/DSWaveformImageViews/UIKit/WaveformLiveView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,35 @@ public class WaveformLiveView: UIView {
self.renderer = renderer
super.init(frame: .zero)
self.contentMode = .redraw

defer { // will call didSet to propagate to sampleLayer
self.configuration = configuration
self.renderer = renderer
}
}

public override init(frame: CGRect) {
self.configuration = Self.defaultConfiguration
self.renderer = LinearWaveformRenderer()
super.init(frame: frame)
contentMode = .redraw

defer { // will call didSet to propagate to sampleLayer
self.configuration = Self.defaultConfiguration
self.renderer = LinearWaveformRenderer()
}
}

required init?(coder: NSCoder) {
self.configuration = Self.defaultConfiguration
self.renderer = LinearWaveformRenderer()
super.init(coder: coder)
contentMode = .redraw

defer { // will call didSet to propagate to sampleLayer
self.configuration = Self.defaultConfiguration
self.renderer = LinearWaveformRenderer()
}
}

/// The sample to be added. Re-draws the waveform with the pre-existing samples and the new one.
Expand Down

0 comments on commit f46cf06

Please sign in to comment.