Browse Source

iOS: Ensured that native file choosers also work in iOS apps

tags/2021-05-28
hogliux 7 years ago
parent
commit
3a8c63f5d4
3 changed files with 52 additions and 7 deletions
  1. +14
    -0
      modules/juce_audio_plugin_client/AU/juce_AUv3_Wrapper.mm
  2. +21
    -5
      modules/juce_gui_basics/native/juce_ios_FileChooser.mm
  3. +17
    -2
      modules/juce_gui_basics/native/juce_ios_UIViewComponentPeer.mm

+ 14
- 0
modules/juce_audio_plugin_client/AU/juce_AUv3_Wrapper.mm View File

@@ -1657,6 +1657,17 @@ JuceAudioUnitv3Base* JuceAudioUnitv3Base::create (AUAudioUnit* audioUnit, AudioC
return new JuceAudioUnitv3 (audioUnit, descr, options, error);
}
#if JUCE_IOS
namespace juce
{
struct UIViewPeerControllerReceiver
{
virtual ~UIViewPeerControllerReceiver();
virtual void setViewController (UIViewController*) = 0;
};
}
#endif
//==============================================================================
class JuceAUViewController
{
@@ -1708,6 +1719,9 @@ public:
#if JUCE_IOS
if (JUCE_IOS_MAC_VIEW* peerView = [[[myself view] subviews] objectAtIndex: 0])
[peerView setContentMode: UIViewContentModeTop];
if (auto* peer = dynamic_cast<UIViewPeerControllerReceiver*> (editor->getPeer()))
peer->setViewController (myself);
#endif
}
}


+ 21
- 5
modules/juce_gui_basics/native/juce_ios_FileChooser.mm View File

@@ -85,11 +85,27 @@ public:
setOpaque (false);
auto chooserBounds = Desktop::getInstance().getDisplays().getMainDisplay().userArea;
setBounds (chooserBounds);
if (SystemStats::isRunningInAppExtensionSandbox())
{
[controller.get() setModalPresentationStyle:UIModalPresentationFullScreen];
if (auto* editorPeer = ComponentPeer::getPeer (0))
{
auto chooserBounds = editorPeer->getComponent().getLocalBounds();
setBounds (chooserBounds);
setAlwaysOnTop (true);
addToDesktop (0);
setAlwaysOnTop (true);
editorPeer->getComponent().addAndMakeVisible (this);
}
}
else
{
auto chooserBounds = Desktop::getInstance().getDisplays().getMainDisplay().userArea;
setBounds (chooserBounds);
setAlwaysOnTop (true);
addToDesktop (0);
}
}
~Native()
@@ -308,7 +324,7 @@ bool FileChooser::isPlatformDialogAvailable()
#if JUCE_DISABLE_NATIVE_FILECHOOSERS
return false;
#else
return [[NSFileManager defaultManager] ubiquityIdentityToken] != nil;
return true;
#endif
}


+ 17
- 2
modules/juce_gui_basics/native/juce_ios_UIViewComponentPeer.mm View File

@@ -163,8 +163,17 @@ using namespace juce;
namespace juce
{
struct UIViewPeerControllerReceiver
{
virtual ~UIViewPeerControllerReceiver();
virtual void setViewController (UIViewController*) = 0;
};
UIViewPeerControllerReceiver::~UIViewPeerControllerReceiver() {}
class UIViewComponentPeer : public ComponentPeer,
public FocusChangeListener
public FocusChangeListener,
public UIViewPeerControllerReceiver
{
public:
UIViewComponentPeer (Component&, int windowStyleFlags, UIView* viewToAttachTo);
@@ -176,6 +185,12 @@ public:
void setTitle (const String& title) override;
void setBounds (const Rectangle<int>&, bool isNowFullScreen) override;
void setViewController (UIViewController* newController) override
{
jassert (controller == nullptr);
controller = [newController retain];
}
Rectangle<int> getBounds() const override { return getBounds (! isSharedWindow); }
Rectangle<int> getBounds (bool global) const;
Point<float> localToGlobal (Point<float> relativePosition) override;
@@ -218,7 +233,7 @@ public:
//==============================================================================
UIWindow* window;
JuceUIView* view;
JuceUIViewController* controller;
UIViewController* controller;
bool isSharedWindow, fullScreen, insideDrawRect, isAppex;
static int64 getMouseTime (UIEvent* e) noexcept


Loading…
Cancel
Save