Skip to content

Commit 0edad2f

Browse files
committed
refactor(android): better addRef/releaseRef node semantics
1 parent 8025d59 commit 0edad2f

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

android/src/main/java/com/ijzerenhein/sharedelement/RNSharedElementNode.java

+13-5
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,24 @@ int getReactTag() {
7070
return mReactTag;
7171
}
7272

73-
int getRefCount() {
74-
return mRefCount;
73+
int addRef() {
74+
return ++mRefCount;
7575
}
7676

77-
void setRefCount(int refCount) {
78-
mRefCount = refCount;
79-
if (mRefCount == 0) {
77+
int releaseRef() {
78+
if (--mRefCount == 0) {
8079
removeDraweeControllerListener(mResolvedView);
8180
stopRetryLoop();
81+
mView = null;
82+
mAncestorView = null;
83+
mStyleConfig = null;
84+
mResolvedView = null;
85+
mContentCache = null;
86+
mContentCallbacks = null;
87+
mStyleCache = null;
88+
mStyleCallbacks = null;
8289
}
90+
return mRefCount;
8391
}
8492

8593
void addHideRef() {

android/src/main/java/com/ijzerenhein/sharedelement/RNSharedElementNodeManager.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ RNSharedElementNode acquire(int reactTag, View view, boolean isParent, View ance
3030
synchronized (mNodes) {
3131
RNSharedElementNode node = mNodes.get(reactTag);
3232
if (node != null) {
33-
node.setRefCount(node.getRefCount() + 1);
33+
node.addRef();
3434
return node;
3535
}
3636
node = new RNSharedElementNode(mContext, reactTag, view, isParent, ancestor, styleConfig);
@@ -41,11 +41,11 @@ RNSharedElementNode acquire(int reactTag, View view, boolean isParent, View ance
4141

4242
int release(RNSharedElementNode node) {
4343
synchronized (mNodes) {
44-
node.setRefCount(node.getRefCount() - 1);
45-
if (node.getRefCount() == 0) {
44+
int refCount = node.releaseRef();
45+
if (refCount == 0) {
4646
mNodes.remove(node.getReactTag());
4747
}
48-
return node.getRefCount();
48+
return refCount;
4949
}
5050
}
5151
}

0 commit comments

Comments
 (0)