535 {
539 nibName:nil
540 bundle:nil];
541
543 UIScreen* screen = [self setUpMockScreen];
544 CGRect viewFrame = screen.bounds;
545 [self setUpMockView:viewControllerMock
546 screen:screen
547 viewFrame:viewFrame
548 convertedFrame:viewFrame];
549
550 CGFloat screenWidth = screen.bounds.size.width;
551 CGFloat screenHeight = screen.bounds.size.height;
552
553
554 CGRect keyboardFrame = CGRectZero;
555 NSNotification* notification =
556 [NSNotification notificationWithName:UIKeyboardWillHideNotification
557 object:nil
558 userInfo:@{
559 @"UIKeyboardFrameEndUserInfoKey" : @(keyboardFrame),
560 @"UIKeyboardAnimationDurationUserInfoKey" : @0.25,
561 @"UIKeyboardIsLocalUserInfoKey" : @(YES)
562 }];
564 XCTAssertTrue(keyboardMode == FlutterKeyboardModeHidden);
565
566
567 keyboardFrame = CGRectZero;
568 notification = [NSNotification notificationWithName:UIKeyboardWillChangeFrameNotification
569 object:nil
570 userInfo:@{
571 @"UIKeyboardFrameEndUserInfoKey" : @(keyboardFrame),
572 @"UIKeyboardAnimationDurationUserInfoKey" : @0.25,
573 @"UIKeyboardIsLocalUserInfoKey" : @(YES)
574 }];
576 XCTAssertTrue(keyboardMode == FlutterKeyboardModeFloating);
577
578
579 keyboardFrame = CGRectMake(0, 0, screenWidth, 0);
580 notification = [NSNotification notificationWithName:UIKeyboardWillChangeFrameNotification
581 object:nil
582 userInfo:@{
583 @"UIKeyboardFrameEndUserInfoKey" : @(keyboardFrame),
584 @"UIKeyboardAnimationDurationUserInfoKey" : @0.25,
585 @"UIKeyboardIsLocalUserInfoKey" : @(YES)
586 }];
588 XCTAssertTrue(keyboardMode == FlutterKeyboardModeHidden);
589
590
591 keyboardFrame = CGRectMake(0, 0, 320, 320);
592 notification = [NSNotification notificationWithName:UIKeyboardWillChangeFrameNotification
593 object:nil
594 userInfo:@{
595 @"UIKeyboardFrameEndUserInfoKey" : @(keyboardFrame),
596 @"UIKeyboardAnimationDurationUserInfoKey" : @0.25,
597 @"UIKeyboardIsLocalUserInfoKey" : @(YES)
598 }];
600 XCTAssertTrue(keyboardMode == FlutterKeyboardModeFloating);
601
602
603 keyboardFrame = CGRectMake(0, 0, screenWidth, 320);
604 notification = [NSNotification notificationWithName:UIKeyboardWillChangeFrameNotification
605 object:nil
606 userInfo:@{
607 @"UIKeyboardFrameEndUserInfoKey" : @(keyboardFrame),
608 @"UIKeyboardAnimationDurationUserInfoKey" : @0.25,
609 @"UIKeyboardIsLocalUserInfoKey" : @(YES)
610 }];
612 XCTAssertTrue(keyboardMode == FlutterKeyboardModeFloating);
613
614
615 keyboardFrame = CGRectMake(0, screenHeight - 320, screenWidth, 320);
616 notification = [NSNotification notificationWithName:UIKeyboardWillChangeFrameNotification
617 object:nil
618 userInfo:@{
619 @"UIKeyboardFrameEndUserInfoKey" : @(keyboardFrame),
620 @"UIKeyboardAnimationDurationUserInfoKey" : @0.25,
621 @"UIKeyboardIsLocalUserInfoKey" : @(YES)
622 }];
624 XCTAssertTrue(keyboardMode == FlutterKeyboardModeDocked);
625
626
627 CGFloat longDecimalHeight = 320.666666666666666;
628 keyboardFrame = CGRectMake(0, screenHeight - longDecimalHeight, screenWidth, longDecimalHeight);
629 notification = [NSNotification notificationWithName:UIKeyboardWillChangeFrameNotification
630 object:nil
631 userInfo:@{
632 @"UIKeyboardFrameEndUserInfoKey" : @(keyboardFrame),
633 @"UIKeyboardAnimationDurationUserInfoKey" : @0.25,
634 @"UIKeyboardIsLocalUserInfoKey" : @(YES)
635 }];
636 keyboardMode = [viewControllerMock calculateKeyboardAttachMode:notification];
637 XCTAssertTrue(keyboardMode == FlutterKeyboardModeDocked);
638
639
640 keyboardFrame = CGRectMake(0, screenHeight - .0000001, screenWidth, longDecimalHeight);
641 notification = [NSNotification notificationWithName:UIKeyboardWillChangeFrameNotification
642 object:nil
643 userInfo:@{
644 @"UIKeyboardFrameEndUserInfoKey" : @(keyboardFrame),
645 @"UIKeyboardAnimationDurationUserInfoKey" : @0.25,
646 @"UIKeyboardIsLocalUserInfoKey" : @(YES)
647 }];
648 keyboardMode = [viewControllerMock calculateKeyboardAttachMode:notification];
649 XCTAssertTrue(keyboardMode == FlutterKeyboardModeHidden);
650
651
652 keyboardFrame = CGRectMake(0, screenHeight, screenWidth, 320);
653 notification = [NSNotification notificationWithName:UIKeyboardWillChangeFrameNotification
654 object:nil
655 userInfo:@{
656 @"UIKeyboardFrameEndUserInfoKey" : @(keyboardFrame),
657 @"UIKeyboardAnimationDurationUserInfoKey" : @0.25,
658 @"UIKeyboardIsLocalUserInfoKey" : @(YES)
659 }];
660 keyboardMode = [viewControllerMock calculateKeyboardAttachMode:notification];
661 XCTAssertTrue(keyboardMode == FlutterKeyboardModeHidden);
662}
FlutterKeyboardMode calculateKeyboardAttachMode:(NSNotification *notification)