Skip to content

Commit e97aaf4

Browse files
author
LisoUseInAIKyrios
authored
fix(YouTube - Hide Shorts components): Correctly hide Shorts if navigation tab is changed using device back button (#3007)
1 parent 92c90ec commit e97aaf4

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

src/main/kotlin/app/revanced/patches/youtube/misc/navigation/NavigationBarHookPatch.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ object NavigationBarHookPatch : BytecodePatch(
3636
NavigationEnumFingerprint,
3737
PivotBarButtonsCreateDrawableViewFingerprint,
3838
PivotBarButtonsCreateResourceViewFingerprint,
39+
PivotBarButtonsViewSetSelectedFingerprint,
3940
NavigationBarHookCallbackFingerprint,
41+
MainActivityOnBackPressedFingerprint,
4042
ActionBarSearchResultsFingerprint,
4143
),
4244
) {
@@ -90,6 +92,29 @@ object NavigationBarHookPatch : BytecodePatch(
9092
}
9193
}
9294

95+
PivotBarButtonsViewSetSelectedFingerprint.resultOrThrow().mutableMethod.apply {
96+
val index = PivotBarButtonsViewSetSelectedFingerprint.indexOfSetViewSelectedInstruction(this)
97+
val instruction = getInstruction<FiveRegisterInstruction>(index)
98+
val viewRegister = instruction.registerC
99+
val isSelectedRegister = instruction.registerD
100+
101+
addInstruction(
102+
index + 1,
103+
"invoke-static { v$viewRegister, v$isSelectedRegister }, " +
104+
"$INTEGRATIONS_CLASS_DESCRIPTOR->navigationTabSelected(Landroid/view/View;Z)V",
105+
)
106+
}
107+
108+
// Hook onto back button pressed. Needed to fix race problem with
109+
// litho filtering based on navigation tab before the tab is updated.
110+
MainActivityOnBackPressedFingerprint.resultOrThrow().mutableMethod.apply {
111+
addInstruction(
112+
0,
113+
"invoke-static { p0 }, " +
114+
"$INTEGRATIONS_CLASS_DESCRIPTOR->onBackPressed(Landroid/app/Activity;)V",
115+
)
116+
}
117+
93118
// Hook the search bar.
94119

95120
// Two different layouts are used at the hooked code.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package app.revanced.patches.youtube.misc.navigation.fingerprints
2+
3+
import app.revanced.patcher.extensions.or
4+
import app.revanced.patcher.fingerprint.MethodFingerprint
5+
import com.android.tools.smali.dexlib2.AccessFlags
6+
7+
internal object MainActivityOnBackPressedFingerprint : MethodFingerprint(
8+
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
9+
returnType = "V",
10+
parameters = listOf(),
11+
customFingerprint = { methodDef, _ ->
12+
(methodDef.definingClass.endsWith("MainActivity;") ||
13+
// Old versions of YouTube called this class "WatchWhileActivity" instead.
14+
methodDef.definingClass.endsWith("WatchWhileActivity;"))
15+
&& methodDef.name == "onBackPressed"
16+
}
17+
)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package app.revanced.patches.youtube.misc.navigation.fingerprints
2+
3+
import app.revanced.patcher.extensions.or
4+
import app.revanced.patcher.fingerprint.MethodFingerprint
5+
import app.revanced.patches.youtube.misc.navigation.fingerprints.PivotBarButtonsViewSetSelectedFingerprint.indexOfSetViewSelectedInstruction
6+
import app.revanced.util.getReference
7+
import app.revanced.util.indexOfFirstInstruction
8+
import com.android.tools.smali.dexlib2.AccessFlags
9+
import com.android.tools.smali.dexlib2.Opcode
10+
import com.android.tools.smali.dexlib2.iface.Method
11+
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
12+
13+
internal object PivotBarButtonsViewSetSelectedFingerprint : MethodFingerprint(
14+
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
15+
parameters = listOf("I", "Z"),
16+
returnType = "V",
17+
customFingerprint = { methodDef, classDef ->
18+
classDef.type == "Lcom/google/android/libraries/youtube/rendering/ui/pivotbar/PivotBar;" &&
19+
indexOfSetViewSelectedInstruction(methodDef) >= 0
20+
}
21+
) {
22+
fun indexOfSetViewSelectedInstruction(methodDef: Method) =
23+
methodDef.indexOfFirstInstruction {
24+
opcode == Opcode.INVOKE_VIRTUAL && getReference<MethodReference>()?.name == "setSelected"
25+
}
26+
}
27+

0 commit comments

Comments
 (0)