  The quantum anomalous Hall (QAH) effect is sometimes observed in twisted
bilayer graphene (tBG) when it is nearly aligned with an encapsulating
hexagonal boron nitride (hBN) layer. We propose that the appearance or absence
of the QAH effect in individual devices could be related to commensurability
between the graphene/graphene and graphene/hBN moir\'e patterns. We identify a
series of points in the $(\theta_{\rm GG},\theta_{\rm GBN})$ twist-angle space
at which the two moir\'e patterns are commensurate, allowing moir\'e band
theory to be applied, and show that the band Chern numbers are in this case
sensitive to a rigid in-plane hBN displacement. Given this property, we argue
that the QAH effect is likely only when i) the $(\theta_{\rm GG},\theta_{\rm
GBN})$ twist-angle-pair is close enough to a commensurate point that the two
moir\'e patterns yield a supermoir\'e pattern with a sufficiently long length
scale, and ii) the supermoir\'e has a percolating topologically non-trivial QAH
phase. For twist angles far from commensurability, the hBN layer acts as a
source of disorder that can destroy the QAH effect. Our proposal can explain a
number of current experimental observations. Further experimental studies that
can test this proposal more directly are suggested.
