What is the best alternative to `canvas.clipRect` with `Region.Op.REPLACE`? : <h2>Background</h2>

<p>I'm working on a library that has a lot of canvas drawing instead of multiple views (available <a href="https://github.com/Quivr/Android-Week-View" rel="noreferrer"><strong>here</strong></a>).</p>

<h2>The problem</h2>

<p>As I work to improve it and make it work for our needs of the app (need some customization), I've noticed there are some lines that are marked as deprecated:</p>

<pre><code>canvas.clipRect(0f, mHeaderHeight + mHeaderRowPadding * 2, mHeaderColumnWidth, height.toFloat(), Region.Op.REPLACE)
</code></pre>

<p>Thing is, I don't think there is a good candidate to replace this line of code with the newer APIs</p>

<h2>What I've found</h2>

<p>Looking at <a href="https://developer.android.com/reference/android/graphics/Canvas.html#clipRect(android.graphics.RectF,%20android.graphics.Region.Op)" rel="noreferrer"><strong>the docs</strong></a>, this is what's written:</p>

<blockquote>
  <p>This method was deprecated in API level 26. Region.Op values other
  than INTERSECT and DIFFERENCE have the ability to expand the clip. The
  canvas clipping APIs are intended to only expand the clip as a result
  of a restore operation. This enables a view parent to clip a canvas to
  clearly define the maximal drawing area of its children. The
  recommended alternative calls are clipRect(RectF) and
  clipOutRect(RectF);</p>
</blockquote>

<p>So I tried using either of those functions, yet both of them caused issues with the drawing of how it used to be.</p>

<p>Looking at the deprecation, it seems that the function itself is marked, but not Region.Op.REPLACE :</p>

<p><a href="https://i.stack.imgur.com/yjhkn.png" rel="noreferrer"><img src="https://i.stack.imgur.com/yjhkn.png" alt="enter image description here"></a></p>

<p>So maybe it doesn't really have an alternative...</p>

<h2>The questions</h2>

<ol>
<li>What is the best alternative in this case?</li>
<li>Why exactly was it deprecated? </li>
<li>As opposed to some deprecated functions, I assume this one should be safe to still use in case I can't find an alternative, right?</li>
</ol>
