@@ -69,11 +69,11 @@ @interface FlutterViewController () <FlutterBinaryMessenger, UIScrollViewDelegat
69
69
/* *
70
70
* Keyboard animation properties
71
71
*/
72
- @property (nonatomic , assign ) CGFloat targetViewInsetBottom;
73
- @property (nonatomic , assign ) CGFloat originalViewInsetBottom;
72
+ @property (nonatomic , assign ) double targetViewInsetBottom;
74
73
@property (nonatomic , retain ) VSyncClient* keyboardAnimationVSyncClient;
75
74
@property (nonatomic , assign ) BOOL keyboardAnimationIsShowing;
76
75
@property (nonatomic , assign ) fml::TimePoint keyboardAnimationStartTime;
76
+ @property (nonatomic , assign ) CGFloat originalViewInsetBottom;
77
77
@property (nonatomic , assign ) BOOL isKeyboardInOrTransitioningFromBackground;
78
78
79
79
// / VSyncClient for touch events delivery frame rate correction.
@@ -575,8 +575,8 @@ - (void)installFirstFrameCallback {
575
575
// Start on the platform thread.
576
576
weakPlatformView->SetNextFrameCallback ([weakSelf = [self getWeakPtr ],
577
577
platformTaskRunner = [_engine.get () platformTaskRunner ],
578
- rasterTaskRunner = [_engine.get () rasterTaskRunner ]]() {
579
- FML_DCHECK (rasterTaskRunner ->RunsTasksOnCurrentThread ());
578
+ RasterTaskRunner = [_engine.get () RasterTaskRunner ]]() {
579
+ FML_DCHECK (RasterTaskRunner ->RunsTasksOnCurrentThread ());
580
580
// Get callback on raster thread and jump back to platform thread.
581
581
platformTaskRunner->PostTask ([weakSelf]() {
582
582
if (weakSelf) {
@@ -1605,55 +1605,7 @@ - (void)startKeyBoardAnimation:(NSTimeInterval)duration {
1605
1605
1606
1606
// Invalidate old vsync client if old animation is not completed.
1607
1607
[self invalidateKeyboardAnimationVSyncClient ];
1608
-
1609
- fml::WeakPtr<FlutterViewController> weakSelf = [self getWeakPtr ];
1610
- FlutterKeyboardAnimationCallback keyboardAnimationCallback = ^(
1611
- fml::TimePoint keyboardAnimationTargetTime) {
1612
- if (!weakSelf) {
1613
- return ;
1614
- }
1615
- fml::scoped_nsobject<FlutterViewController> flutterViewController (
1616
- [(FlutterViewController*)weakSelf.get () retain ]);
1617
- if (!flutterViewController) {
1618
- return ;
1619
- }
1620
-
1621
- // If the view controller's view is not loaded, bail out.
1622
- if (!flutterViewController.get ().isViewLoaded ) {
1623
- return ;
1624
- }
1625
- // If the view for tracking keyboard animation is nil, means it is not
1626
- // created, bail out.
1627
- if ([flutterViewController keyboardAnimationView ] == nil ) {
1628
- return ;
1629
- }
1630
- // If keyboardAnimationVSyncClient is nil, means the animation ends.
1631
- // And should bail out.
1632
- if (flutterViewController.get ().keyboardAnimationVSyncClient == nil ) {
1633
- return ;
1634
- }
1635
-
1636
- if ([flutterViewController keyboardAnimationView ].superview == nil ) {
1637
- // Ensure the keyboardAnimationView is in view hierarchy when animation running.
1638
- [flutterViewController.get ().view addSubview: [flutterViewController keyboardAnimationView ]];
1639
- }
1640
-
1641
- if ([flutterViewController keyboardSpringAnimation ] == nil ) {
1642
- if (flutterViewController.get ().keyboardAnimationView .layer .presentationLayer ) {
1643
- flutterViewController.get ()->_viewportMetrics .physical_view_inset_bottom =
1644
- flutterViewController.get ()
1645
- .keyboardAnimationView .layer .presentationLayer .frame .origin .y ;
1646
- [flutterViewController updateViewportMetricsIfNeeded ];
1647
- }
1648
- } else {
1649
- fml::TimeDelta timeElapsed =
1650
- keyboardAnimationTargetTime - flutterViewController.get ().keyboardAnimationStartTime ;
1651
- flutterViewController.get ()->_viewportMetrics .physical_view_inset_bottom =
1652
- [[flutterViewController keyboardSpringAnimation ] curveFunction: timeElapsed.ToSecondsF ()];
1653
- [flutterViewController updateViewportMetricsIfNeeded ];
1654
- }
1655
- };
1656
- [self setupKeyboardAnimationVsyncClient: keyboardAnimationCallback];
1608
+ [self setupKeyboardAnimationVsyncClient ];
1657
1609
VSyncClient* currentVsyncClient = _keyboardAnimationVSyncClient;
1658
1610
1659
1611
[UIView animateWithDuration: duration
@@ -1696,28 +1648,45 @@ - (void)setupKeyboardSpringAnimationIfNeeded:(CAAnimation*)keyboardAnimation {
1696
1648
toValue: self .targetViewInsetBottom]);
1697
1649
}
1698
1650
1699
- - (void )setupKeyboardAnimationVsyncClient :
1700
- (FlutterKeyboardAnimationCallback)keyboardAnimationCallback {
1701
- if (!keyboardAnimationCallback) {
1702
- return ;
1703
- }
1704
- NSAssert (_keyboardAnimationVSyncClient == nil ,
1705
- @" _keyboardAnimationVSyncClient must be nil when setup" );
1651
+ - (void )setupKeyboardAnimationVsyncClient {
1652
+ auto callback = [weakSelf =
1653
+ [self getWeakPtr ]](std::unique_ptr<flutter::FrameTimingsRecorder> recorder) {
1654
+ if (!weakSelf) {
1655
+ return ;
1656
+ }
1657
+ fml::scoped_nsobject<FlutterViewController> flutterViewController (
1658
+ [(FlutterViewController*)weakSelf.get () retain ]);
1659
+ if (!flutterViewController) {
1660
+ return ;
1661
+ }
1706
1662
1707
- // Make sure the new viewport metrics get sent after the begin frame event has processed.
1708
- fml::scoped_nsprotocol<FlutterKeyboardAnimationCallback> animationCallback (
1709
- [keyboardAnimationCallback copy ]);
1710
- auto uiCallback = [animationCallback,
1711
- engine = _engine](std::unique_ptr<flutter::FrameTimingsRecorder> recorder) {
1712
- fml::TimeDelta frameInterval = recorder->GetVsyncTargetTime () - recorder->GetVsyncStartTime ();
1713
- fml::TimePoint keyboardAnimationTargetTime = recorder->GetVsyncTargetTime () + frameInterval;
1714
- [engine platformTaskRunner ]->PostTask ([animationCallback, keyboardAnimationTargetTime] {
1715
- animationCallback.get ()(keyboardAnimationTargetTime);
1716
- });
1717
- };
1663
+ if ([flutterViewController keyboardAnimationView ].superview == nil ) {
1664
+ // Ensure the keyboardAnimationView is in view hierarchy when animation running.
1665
+ [flutterViewController.get ().view addSubview: [flutterViewController keyboardAnimationView ]];
1666
+ }
1718
1667
1719
- _keyboardAnimationVSyncClient = [[VSyncClient alloc ] initWithTaskRunner: [_engine uiTaskRunner ]
1720
- callback: uiCallback];
1668
+ if ([flutterViewController keyboardSpringAnimation ] == nil ) {
1669
+ if (flutterViewController.get ().keyboardAnimationView .layer .presentationLayer ) {
1670
+ flutterViewController.get ()->_viewportMetrics .physical_view_inset_bottom =
1671
+ flutterViewController.get ()
1672
+ .keyboardAnimationView .layer .presentationLayer .frame .origin .y ;
1673
+ [flutterViewController updateViewportMetricsIfNeeded ];
1674
+ }
1675
+ } else {
1676
+ fml::TimeDelta timeElapsed = recorder.get ()->GetVsyncTargetTime () -
1677
+ flutterViewController.get ().keyboardAnimationStartTime ;
1678
+
1679
+ flutterViewController.get ()->_viewportMetrics .physical_view_inset_bottom =
1680
+ [[flutterViewController keyboardSpringAnimation ] curveFunction: timeElapsed.ToSecondsF ()];
1681
+ [flutterViewController updateViewportMetricsIfNeeded ];
1682
+ }
1683
+ };
1684
+ flutter::Shell& shell = [_engine.get () shell ];
1685
+ NSAssert (_keyboardAnimationVSyncClient == nil ,
1686
+ @" _keyboardAnimationVSyncClient must be nil when setup" );
1687
+ _keyboardAnimationVSyncClient =
1688
+ [[VSyncClient alloc ] initWithTaskRunner: shell.GetTaskRunners ().GetPlatformTaskRunner ()
1689
+ callback: callback];
1721
1690
_keyboardAnimationVSyncClient.allowPauseAfterVsync = NO ;
1722
1691
[_keyboardAnimationVSyncClient await ];
1723
1692
}
0 commit comments