Skip to content

Instantly share code, notes, and snippets.

@joshuaseltzer
Created November 18, 2024 02:09
Show Gist options
  • Save joshuaseltzer/bc52e5f3951fa9c806e77de6763279ef to your computer and use it in GitHub Desktop.
Save joshuaseltzer/bc52e5f3951fa9c806e77de6763279ef to your computer and use it in GitHub Desktop.
Hide Buttons in the Action Bar
// hide useless buttons under the video player
static BOOL shouldHideCell(ASNodeController *nodeController, NSArray <NSString *> *identifiers, NSArray <NSString *> *titles) {
for (id child in [nodeController children]) {
if ([child isKindOfClass:%c(ELMComponent)]) {
ELMComponent *elmChild = (ELMComponent *)child;
if ([[elmChild templateURI] containsString:@"video_action_button_with_vm_input"]) {
return shouldHideCell([elmChild materializedInstance], identifiers, titles);
} else {
for (NSString *identifier in identifiers) {
if ([[elmChild templateURI] containsString:identifier]) {
return YES;
}
}
if ([[elmChild templateURI] containsString:@"button.eml"]) {
ASDisplayNode *childDisplayNode = [elmChild node];
for (NSString *identifier in identifiers) {
if ([[childDisplayNode description] containsString:identifier]) {
return YES;
}
}
for (id yogaChild in [childDisplayNode yogaChildren]) {
if ([yogaChild isKindOfClass:%c(ELMTextNode)]) {
ELMTextNode *elmTextNode = (ELMTextNode *)yogaChild;
for (NSString *title in titles) {
if ([[elmTextNode.attributedText string] isEqualToString:title]) {
return YES;
}
}
}
}
}
}
}
if ([child isKindOfClass:%c(ELMNodeController)]) {
NSArray <ELMComponent *> *elmChildren = [(ELMNodeController *)child children];
for (ELMComponent *elmChild in elmChildren) {
for (NSString *identifier in identifiers) {
if ([[elmChild templateURI] containsString:identifier]) {
return YES;
}
}
}
}
if ([child isKindOfClass:%c(ASNodeController)]) {
ASDisplayNode *childNode = ((ASNodeController *)child).node; // ELMContainerNode
NSArray *yogaChildren = childNode.yogaChildren;
for (ASDisplayNode *displayNode in yogaChildren) {
if ([identifiers containsObject:displayNode.accessibilityIdentifier]) {
return YES;
}
}
return shouldHideCell(child, identifiers, titles);
}
return NO;
}
return NO;
}
%hook ASCollectionView
// hide useless items under the video player
- (CGSize)sizeForElement:(ASCollectionElement *)element {
if ([self.accessibilityIdentifier isEqualToString:@"id.video.scrollable_action_bar"]) {
ASCellNode *node = [element node];
ASNodeController *nodeController = [node controller];
if (shouldHideCell(nodeController, @[@"id.video.remix.button", @"clip_button.eml"], @[@"Thanks", @"Report"])) {
return CGSizeZero;
}
}
return %orig;
}
%end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment