Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(YouTube - Hide Shorts components): Correctly hide Shorts if navigation tab is changed using device back button #3007

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ object NavigationBarHookPatch : BytecodePatch(
NavigationEnumFingerprint,
PivotBarButtonsCreateDrawableViewFingerprint,
PivotBarButtonsCreateResourceViewFingerprint,
PivotBarButtonsViewSetSelectedFingerprint,
NavigationBarHookCallbackFingerprint,
MainActivityOnBackPressedFingerprint,
ActionBarSearchResultsFingerprint,
),
) {
Expand Down Expand Up @@ -90,6 +92,29 @@ object NavigationBarHookPatch : BytecodePatch(
}
}

PivotBarButtonsViewSetSelectedFingerprint.resultOrThrow().mutableMethod.apply {
val index = PivotBarButtonsViewSetSelectedFingerprint.indexOfSetViewSelectedInstruction(this)
val instruction = getInstruction<FiveRegisterInstruction>(index)
val viewRegister = instruction.registerC
val isSelectedRegister = instruction.registerD

addInstruction(
index + 1,
"invoke-static { v$viewRegister, v$isSelectedRegister }, " +
"$INTEGRATIONS_CLASS_DESCRIPTOR->navigationTabSelected(Landroid/view/View;Z)V",
)
}

// Hook onto back button pressed. Needed to fix race problem with
// litho filtering based on navigation tab before the tab is updated.
MainActivityOnBackPressedFingerprint.resultOrThrow().mutableMethod.apply {
addInstruction(
0,
"invoke-static { p0 }, " +
"$INTEGRATIONS_CLASS_DESCRIPTOR->onBackPressed(Landroid/app/Activity;)V",
)
}

// Hook the search bar.

// Two different layouts are used at the hooked code.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package app.revanced.patches.youtube.misc.navigation.fingerprints

import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import com.android.tools.smali.dexlib2.AccessFlags

internal object MainActivityOnBackPressedFingerprint : MethodFingerprint(
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
returnType = "V",
parameters = listOf(),
customFingerprint = { methodDef, _ ->
(methodDef.definingClass.endsWith("MainActivity;") ||
// Old versions of YouTube called this class "WatchWhileActivity" instead.
methodDef.definingClass.endsWith("WatchWhileActivity;"))
&& methodDef.name == "onBackPressed"
}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package app.revanced.patches.youtube.misc.navigation.fingerprints

import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patches.youtube.misc.navigation.fingerprints.PivotBarButtonsViewSetSelectedFingerprint.indexOfSetViewSelectedInstruction
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstruction
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.Method
import com.android.tools.smali.dexlib2.iface.reference.MethodReference

internal object PivotBarButtonsViewSetSelectedFingerprint : MethodFingerprint(
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("I", "Z"),
returnType = "V",
customFingerprint = { methodDef, classDef ->
classDef.type == "Lcom/google/android/libraries/youtube/rendering/ui/pivotbar/PivotBar;" &&
indexOfSetViewSelectedInstruction(methodDef) >= 0
}
) {
fun indexOfSetViewSelectedInstruction(methodDef: Method) =
methodDef.indexOfFirstInstruction {
opcode == Opcode.INVOKE_VIRTUAL && getReference<MethodReference>()?.name == "setSelected"
}
}

Loading