Skip to content

Commit 9ded397

Browse files
author
tkzcfc
committed
Merge branch 'release/2.x' into dev_custom
* release/2.x: Fix ios editbox keyboard handling (axmolengine#2795) Add support for extracting the previous scene from the scene stack (axmolengine#2793)
2 parents 6f38634 + 939f6b1 commit 9ded397

File tree

4 files changed

+70
-12
lines changed

4 files changed

+70
-12
lines changed

core/base/Director.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,39 @@ void Director::popToSceneStackLevel(int level)
966966
_sendCleanupToScene = true;
967967
}
968968

969+
Scene* Director::popPreviousSceneOut()
970+
{
971+
if (_nextScene)
972+
{
973+
return nullptr;
974+
}
975+
976+
const auto numScenes = _scenesStack.size();
977+
978+
if (numScenes < 2)
979+
{
980+
return nullptr;
981+
}
982+
983+
const auto previousSceneIndex = numScenes - 2;
984+
985+
auto previousScene = _scenesStack.at(previousSceneIndex);
986+
previousScene->retain();
987+
previousScene->autorelease();
988+
989+
#if AX_ENABLE_GC_FOR_NATIVE_OBJECTS
990+
auto sEngine = ScriptEngineManager::getInstance()->getScriptEngine();
991+
if (sEngine)
992+
{
993+
sEngine->releaseScriptObject(this, previousScene);
994+
}
995+
#endif // AX_ENABLE_GC_FOR_NATIVE_OBJECTS
996+
997+
_scenesStack.erase(previousSceneIndex);
998+
999+
return previousScene;
1000+
}
1001+
9691002
void Director::end()
9701003
{
9711004
_cleanupDirectorInNextLoop = true;

core/base/Director.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,15 @@ class AX_DLL Director
316316
*/
317317
void replaceScene(Scene* scene);
318318

319+
/** Removes the previous scene from the stack if it exists, and returns it
320+
* If there are less than 2 scenes in the stack, or if there is a
321+
* scene switch about to occur, then this call would be invalid, and a nullptr
322+
* will be returned.
323+
*
324+
* Returns previous scene or nullptr if invalid
325+
*/
326+
Scene* popPreviousSceneOut();
327+
319328
/** Ends the execution, releases the running scene.
320329
* @lua endToLua
321330
*/

core/platform/ios/Device-ios.mm

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -904,13 +904,24 @@ static bool _initWithString(std::string_view text,
904904
return Device::Orientation::Portrait; // fallback
905905
}
906906

907+
static bool isPhone()
908+
{
909+
#if !defined(AX_TARGET_OS_TVOS)
910+
return [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone;
911+
#else
912+
return false;
913+
#endif
914+
}
907915
Device::Orientation Device::resolveOrientation()
908916
{
909917
auto supported = getSupportedOrientations();
910918
auto preferred = getPreferredOrientation();
911919
auto physical = getPhysicalOrientation();
912920

913921
auto tryUse = [&](Orientation o) -> Orientation {
922+
if (isPhone() && o == Orientation::ReversePortrait)
923+
return Orientation::Portrait; // iPhone treats ReversePortrait as Portrait
924+
914925
return ((supported & toMask(o)) == toMask(o)) ? o : Orientation::Unknown;
915926
};
916927

core/platform/ios/EARenderView-ios.mm

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ @implementation EARenderView
103103
@synthesize isKeyboardShown;
104104
@synthesize originalRect = originalRect_;
105105

106+
static ax::Rect convertKeyboardRectToViewport(CGRect rect, CGSize viewSize)
107+
{
108+
float flippedY = viewSize.height - rect.origin.y - rect.size.height;
109+
return ax::Rect(rect.origin.x, flippedY, rect.size.width, rect.size.height);
110+
}
111+
106112
+ (Class)layerClass
107113
{
108114
#if defined(AX_USE_METAL)
@@ -661,12 +667,14 @@ - (void)onUIKeyboardNotification:(NSNotification*)notif
661667
auto renderView = ax::Director::getInstance()->getRenderView();
662668
float scaleX = renderView->getScaleX();
663669
float scaleY = renderView->getScaleY();
670+
671+
const auto backingScaleFactor = self.contentScaleFactor;
664672

665673
// Convert to pixel coordinates
666674
begin = CGRectApplyAffineTransform(begin,
667-
CGAffineTransformScale(CGAffineTransformIdentity, self.contentScaleFactor, self.contentScaleFactor));
675+
CGAffineTransformScale(CGAffineTransformIdentity, backingScaleFactor, backingScaleFactor));
668676
end = CGRectApplyAffineTransform(end,
669-
CGAffineTransformScale(CGAffineTransformIdentity, self.contentScaleFactor, self.contentScaleFactor));
677+
CGAffineTransformScale(CGAffineTransformIdentity, backingScaleFactor, backingScaleFactor));
670678

671679
// Adjust for viewport offset if needed
672680
float offestY = renderView->getViewPortRect().origin.y;
@@ -684,19 +692,19 @@ - (void)onUIKeyboardNotification:(NSNotification*)notif
684692
CGAffineTransformScale(CGAffineTransformIdentity, 1.0f / scaleX, 1.0f / scaleY));
685693

686694
// Fill notification info for Axmol IME dispatcher
695+
auto winSize = originalRect_.size;
696+
CGSize viewSize = CGSizeMake(winSize.width * backingScaleFactor / scaleX,
697+
winSize.height * backingScaleFactor / scaleY);
698+
687699
ax::IMEKeyboardNotificationInfo notiInfo;
688-
notiInfo.begin = ax::Rect(begin.origin.x, begin.origin.y, begin.size.width, begin.size.height);
689-
notiInfo.end = ax::Rect(end.origin.x, end.origin.y, end.size.width, end.size.height);
690-
notiInfo.duration = (float)aniDuration;
700+
notiInfo.begin = convertKeyboardRectToViewport(begin, viewSize);
701+
notiInfo.end = convertKeyboardRectToViewport(end, viewSize);
702+
notiInfo.duration = aniDuration;
691703

692704
ax::IMEDispatcher* dispatcher = ax::IMEDispatcher::sharedDispatcher();
693705
if (UIKeyboardWillShowNotification == type)
694706
{
695707
dispatcher->dispatchKeyboardWillShow(notiInfo);
696-
697-
// Move the whole render view up by keyboard height
698-
CGFloat distance = end.size.height;
699-
[self doAnimationWhenKeyboardMoveWithDuration:aniDuration distance:distance];
700708
}
701709
else if (UIKeyboardDidShowNotification == type)
702710
{
@@ -706,9 +714,6 @@ - (void)onUIKeyboardNotification:(NSNotification*)notif
706714
else if (UIKeyboardWillHideNotification == type)
707715
{
708716
dispatcher->dispatchKeyboardWillHide(notiInfo);
709-
710-
// Restore to original rect
711-
[self doAnimationWhenKeyboardMoveWithDuration:aniDuration distance:0.0f];
712717
}
713718
else if (UIKeyboardDidHideNotification == type)
714719
{

0 commit comments

Comments
 (0)