Skip to content

Commit ebdd93f

Browse files
authored
release: v0.2.0 (#2)
## Feature - support iOS
2 parents a41f82a + c5d59e3 commit ebdd93f

11 files changed

Lines changed: 97 additions & 208 deletions

File tree

.github/FUNDING.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# These are supported funding model platforms
2+
3+
buy_me_a_coffee: arang

.github/actions/setup/action.yml

Lines changed: 0 additions & 27 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 0 additions & 157 deletions
This file was deleted.

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ Quickly and easily check if your app is multiwindow
88

99
![image](https://github.com/user-attachments/assets/945aac7c-c5a5-42dd-8e50-5527c0ea77d4)
1010

11+
- iOS, iPad OS
12+
13+
![image](https://github.com/user-attachments/assets/945aac7c-c5a5-42dd-8e50-5527c0ea77d4)
14+
1115
## Installation
1216

1317
```sh

example/ios/example.xcodeproj/project.pbxproj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -480,8 +480,11 @@
480480
);
481481
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)";
482482
PRODUCT_NAME = example;
483+
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
484+
SUPPORTS_MACCATALYST = NO;
483485
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
484486
SWIFT_VERSION = 5.0;
487+
TARGETED_DEVICE_FAMILY = "1,2";
485488
VERSIONING_SYSTEM = "apple-generic";
486489
};
487490
name = Debug;
@@ -506,7 +509,10 @@
506509
);
507510
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)";
508511
PRODUCT_NAME = example;
512+
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
513+
SUPPORTS_MACCATALYST = NO;
509514
SWIFT_VERSION = 5.0;
515+
TARGETED_DEVICE_FAMILY = "1,2";
510516
VERSIONING_SYSTEM = "apple-generic";
511517
};
512518
name = Release;
@@ -580,10 +586,7 @@
580586
"-DFOLLY_USE_LIBCPP=1",
581587
"-DFOLLY_CFG_NO_COROUTINES=1",
582588
);
583-
OTHER_LDFLAGS = (
584-
"$(inherited)",
585-
" ",
586-
);
589+
OTHER_LDFLAGS = "$(inherited) ";
587590
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
588591
SDKROOT = iphoneos;
589592
USE_HERMES = true;
@@ -651,10 +654,7 @@
651654
"-DFOLLY_USE_LIBCPP=1",
652655
"-DFOLLY_CFG_NO_COROUTINES=1",
653656
);
654-
OTHER_LDFLAGS = (
655-
"$(inherited)",
656-
" ",
657-
);
657+
OTHER_LDFLAGS = "$(inherited) ";
658658
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
659659
SDKROOT = iphoneos;
660660
USE_HERMES = true;

example/ios/example/Info.plist

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
<true/>
2727
<key>NSAppTransportSecurity</key>
2828
<dict>
29-
<!-- Do not change NSAllowsArbitraryLoads to true, or you will risk app rejection! -->
3029
<key>NSAllowsArbitraryLoads</key>
3130
<false/>
3231
<key>NSAllowsLocalNetworking</key>
@@ -40,12 +39,27 @@
4039
<array>
4140
<string>armv7</string>
4241
</array>
42+
<key>UIRequiresFullScreen</key>
43+
<false/>
44+
<key>UIStatusBarHidden</key>
45+
<false/>
46+
<key>UIStatusBarStyle</key>
47+
<string></string>
4348
<key>UISupportedInterfaceOrientations</key>
4449
<array>
50+
<string>UIInterfaceOrientationLandscapeLeft</string>
51+
<string>UIInterfaceOrientationLandscapeRight</string>
4552
<string>UIInterfaceOrientationPortrait</string>
53+
</array>
54+
<key>UISupportedInterfaceOrientations~ipad</key>
55+
<array>
4656
<string>UIInterfaceOrientationLandscapeLeft</string>
4757
<string>UIInterfaceOrientationLandscapeRight</string>
58+
<string>UIInterfaceOrientationPortrait</string>
59+
<string>UIInterfaceOrientationPortraitUpsideDown</string>
4860
</array>
61+
<key>Supported mu</key>
62+
<string></string>
4963
<key>UIViewControllerBasedStatusBarAppearance</key>
5064
<false/>
5165
</dict>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
#import <React/RCTBridgeModule.h>
22
#import <React/RCTViewManager.h>
3+
#import <React/RCTEventEmitter.h>

ios/IsMultiWindow.mm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
#import <Foundation/Foundation.h>
12
#import <React/RCTBridgeModule.h>
3+
#import <React/RCTEventEmitter.h>
24

3-
@interface RCT_EXTERN_MODULE(IsMultiWindow, NSObject)
5+
@interface RCT_EXTERN_MODULE(IsMultiWindow, RCTEventEmitter)
46

5-
RCT_EXTERN_METHOD(multiply:(float)a withB:(float)b
6-
withResolver:(RCTPromiseResolveBlock)resolve
7-
withRejecter:(RCTPromiseRejectBlock)reject)
7+
RCT_EXTERN_METHOD(isMultiWindowMode:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
88

99
+ (BOOL)requiresMainQueueSetup
1010
{

ios/IsMultiWindow.swift

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,60 @@
1-
@objc(IsMultiWindow)
2-
class IsMultiWindow: NSObject {
1+
import UIKit
2+
import React
33

4-
@objc(multiply:withB:withResolver:withRejecter:)
5-
func multiply(a: Float, b: Float, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void {
6-
resolve(a*b)
4+
@objc(IsMultiWindow)
5+
class IsMultiWindow: RCTEventEmitter {
6+
public static var emitter: RCTEventEmitter!
7+
8+
override init() {
9+
super.init()
10+
IsMultiWindow.emitter = self
11+
addObserver()
12+
}
13+
14+
override func supportedEvents() -> [String]! {
15+
return ["onMultiWindowModeChanged"]
16+
}
17+
18+
@objc func addObserver() {
19+
NotificationCenter.default.addObserver(self,
20+
selector: #selector(didRCTWindowFrameDidChange),
21+
name: NSNotification.Name.RCTWindowFrameDidChange,
22+
object: nil)
23+
}
24+
25+
@objc func removeObserver() {
26+
NotificationCenter.default.removeObserver(self,
27+
name: NSNotification.Name.RCTWindowFrameDidChange,
28+
object: nil)
29+
}
30+
31+
@objc func didRCTWindowFrameDidChange(notification: Notification) {
32+
if let screen = notification.object as? UIApplicationDelegate {
33+
let window = (screen.window) as? UIWindow
34+
let updatedBounds = window?.bounds
35+
let fullScreenSize = UIScreen.main.bounds
36+
37+
IsMultiWindow.emitter.sendEvent(
38+
withName: "onMultiWindowModeChanged",
39+
body: !(updatedBounds!.width == fullScreenSize.width && updatedBounds!.height == fullScreenSize.height)
40+
)
41+
}
42+
}
43+
44+
@objc(isMultiWindowMode:rejecter:)
45+
func isMultiWindowMode(_ resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
46+
DispatchQueue.main.async {
47+
let fullScreenSize = UIScreen.main.bounds
48+
guard let keyWindow = UIApplication.shared.connectedScenes
49+
.filter({$0.activationState == .foregroundActive})
50+
.compactMap({$0 as? UIWindowScene})
51+
.first?.windows
52+
.filter({$0.isKeyWindow}).first else {
53+
resolve(false)
54+
return
55+
}
56+
57+
resolve(!(keyWindow.bounds.width == fullScreenSize.width && keyWindow.bounds.height == fullScreenSize.height))
58+
}
759
}
860
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-is-multi-window",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"description": "Quickly and easily check if your app is multiwindowed",
55
"source": "./src/index.tsx",
66
"main": "./lib/commonjs/index.js",

0 commit comments

Comments
 (0)