Skip to content

Commit

Permalink
Forward a11y methods from FlutterSwitchSemanticsObject (flutter#25465)
Browse files Browse the repository at this point in the history
  • Loading branch information
goderbauer authored Apr 13, 2021
1 parent 0d96685 commit 04cd0db
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
32 changes: 32 additions & 0 deletions shell/platform/darwin/ios/framework/Source/SemanticsObject.mm
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ - (void)forwardInvocation:(NSInvocation*)anInvocation {
[anInvocation invoke];
}

// The following methods are explicitly forwarded to the wrapped SemanticsObject because the
// forwarding logic above doesn't apply to them since they are also implemented in the UISwitch
// class, the base class.

- (CGRect)accessibilityFrame {
return [_semanticsObject accessibilityFrame];
}
Expand Down Expand Up @@ -97,6 +101,34 @@ - (NSString*)accessibilityValue {
}
}

- (BOOL)accessibilityActivate {
return [_semanticsObject accessibilityActivate];
}

- (void)accessibilityIncrement {
[_semanticsObject accessibilityIncrement];
}

- (void)accessibilityDecrement {
[_semanticsObject accessibilityDecrement];
}

- (BOOL)accessibilityScroll:(UIAccessibilityScrollDirection)direction {
return [_semanticsObject accessibilityScroll:direction];
}

- (BOOL)accessibilityPerformEscape {
return [_semanticsObject accessibilityPerformEscape];
}

- (void)accessibilityElementDidBecomeFocused {
[_semanticsObject accessibilityElementDidBecomeFocused];
}

- (void)accessibilityElementDidLoseFocus {
[_semanticsObject accessibilityElementDidLoseFocus];
}

@end // FlutterSwitchSemanticsObject

@implementation FlutterCustomAccessibilityAction {
Expand Down
31 changes: 31 additions & 0 deletions shell/platform/darwin/ios/framework/Source/SemanticsObjectTest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,35 @@ - (void)testSemanticsObjectAndPlatformViewSemanticsContainerDontHaveRetainCycle
XCTAssertNil(weakObject);
}

- (void)testFlutterSwitchSemanticsObjectForwardsCalls {
SemanticsObject* mockSemanticsObject = OCMClassMock([SemanticsObject class]);
FlutterSwitchSemanticsObject* switchObj =
[[FlutterSwitchSemanticsObject alloc] initWithSemanticsObject:mockSemanticsObject];
OCMStub([mockSemanticsObject accessibilityActivate]).andReturn(YES);
OCMStub([mockSemanticsObject accessibilityScroll:UIAccessibilityScrollDirectionRight])
.andReturn(NO);
OCMStub([mockSemanticsObject accessibilityPerformEscape]).andReturn(YES);

XCTAssertTrue([switchObj accessibilityActivate]);
OCMVerify([mockSemanticsObject accessibilityActivate]);

[switchObj accessibilityIncrement];
OCMVerify([mockSemanticsObject accessibilityIncrement]);

[switchObj accessibilityDecrement];
OCMVerify([mockSemanticsObject accessibilityDecrement]);

XCTAssertFalse([switchObj accessibilityScroll:UIAccessibilityScrollDirectionRight]);
OCMVerify([mockSemanticsObject accessibilityScroll:UIAccessibilityScrollDirectionRight]);

XCTAssertTrue([switchObj accessibilityPerformEscape]);
OCMVerify([mockSemanticsObject accessibilityPerformEscape]);

[switchObj accessibilityElementDidBecomeFocused];
OCMVerify([mockSemanticsObject accessibilityElementDidBecomeFocused]);

[switchObj accessibilityElementDidLoseFocus];
OCMVerify([mockSemanticsObject accessibilityElementDidLoseFocus]);
}

@end

0 comments on commit 04cd0db

Please sign in to comment.