Skip to content

Commit

Permalink
Skip view injection when in edit mode
Browse files Browse the repository at this point in the history
Closes #4305

RELNOTES=Skip view injection when in edit mode for previews.
PiperOrigin-RevId: 640680452
  • Loading branch information
Edson Moraes Menegatti authored and Dagger Team committed Jun 10, 2024
1 parent 8b3b370 commit 80b09b9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ public void generate() {
XFiler.Mode.Isolating);
}


/**
* Returns a pass-through constructor matching the base class's provided constructorElement. The
* generated constructor simply calls super(), then inject().
Expand All @@ -99,7 +98,9 @@ public void generate() {
* <pre>
* Hilt_$CLASS(Context context, ...) {
* super(context, ...);
* inject();
* if (!isInEditMode()) {
* inject();
* }
* }
* </pre>
*/
Expand All @@ -117,7 +118,9 @@ private MethodSpec constructorMethod(XConstructorElement constructor) {
AnnotationSpec.builder(AndroidClassNames.TARGET_API).addMember("value", "21").build());
}

builder.addStatement("inject()");
builder.beginControlFlow("if(!isInEditMode())")
.addStatement("inject()")
.endControlFlow();

return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,18 @@ public void copyConstructorParametersConvertsAndroidInternalNullableToExternal()
JOINER.join(
" Hilt_MyView(Context p0, @Nullable AttributeSet p1) {",
" super(p0, p1);",
" inject();",
" if(!isInEditMode()) {",
" inject();",
" }",
" }"));
} else {
stringSubject.contains(
JOINER.join(
" Hilt_MyView(Context context, @Nullable AttributeSet attrs) {",
" super(context, attrs);",
" inject();",
" if(!isInEditMode()) {",
" inject();",
" }",
" }"));
}
});
Expand Down

0 comments on commit 80b09b9

Please sign in to comment.