@momo-kits/reserved-regions 0.0.0-stage → 0.167.1-duo.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/ReservedRegions.podspec +20 -0
- package/ios/RNReservedRegionsView.h +10 -0
- package/ios/RNReservedRegionsView.mm +95 -0
- package/package.json +41 -4
- package/src/RNReservedRegionsViewNativeComponent.ts +17 -0
- package/src/index.tsx +57 -0
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 dung.pham2
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = "ReservedRegions"
|
|
7
|
+
s.version = package["version"]
|
|
8
|
+
s.summary = package["description"]
|
|
9
|
+
s.homepage = package["homepage"]
|
|
10
|
+
s.license = package["license"]
|
|
11
|
+
s.authors = package["author"]
|
|
12
|
+
|
|
13
|
+
s.platforms = { :ios => min_ios_version_supported }
|
|
14
|
+
s.source = { :git => "https://www.npmjs.com/.git", :tag => "#{s.version}" }
|
|
15
|
+
|
|
16
|
+
s.source_files = "ios/**/*.{h,m,mm}"
|
|
17
|
+
s.private_header_files = "ios/**/*.h"
|
|
18
|
+
|
|
19
|
+
install_modules_dependencies(s)
|
|
20
|
+
end
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
#import "RNReservedRegionsView.h"
|
|
2
|
+
|
|
3
|
+
#import <react/renderer/components/ReservedRegionsSpec/ComponentDescriptors.h>
|
|
4
|
+
#import <react/renderer/components/ReservedRegionsSpec/EventEmitters.h>
|
|
5
|
+
#import <react/renderer/components/ReservedRegionsSpec/Props.h>
|
|
6
|
+
#import <react/renderer/components/ReservedRegionsSpec/RCTComponentViewHelpers.h>
|
|
7
|
+
|
|
8
|
+
#import "RCTFabricComponentsPlugins.h"
|
|
9
|
+
|
|
10
|
+
using namespace facebook::react;
|
|
11
|
+
|
|
12
|
+
@interface RNReservedRegionsView () <RCTRNReservedRegionsViewViewProtocol>
|
|
13
|
+
@end
|
|
14
|
+
|
|
15
|
+
@implementation RNReservedRegionsView {
|
|
16
|
+
std::vector<double> _lastOcclusion;
|
|
17
|
+
BOOL _hasReported;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
+ (ComponentDescriptorProvider)componentDescriptorProvider {
|
|
21
|
+
return concreteComponentDescriptorProvider<RNReservedRegionsViewComponentDescriptor>();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
- (instancetype)initWithFrame:(CGRect)frame {
|
|
25
|
+
if (self = [super initWithFrame:frame]) {
|
|
26
|
+
static const auto defaultProps = std::make_shared<const RNReservedRegionsViewProps>();
|
|
27
|
+
_props = defaultProps;
|
|
28
|
+
self.userInteractionEnabled = NO;
|
|
29
|
+
}
|
|
30
|
+
return self;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// reading reserved regions inside layoutSubviews / updateProperties lets UIKit call them
|
|
34
|
+
// again when the regions change, e.g. the status bar cluster growing for a call
|
|
35
|
+
- (void)layoutSubviews {
|
|
36
|
+
[super layoutSubviews];
|
|
37
|
+
[self reportRegions];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
- (void)updateProperties {
|
|
41
|
+
if (@available(iOS 26.0, *)) {
|
|
42
|
+
[super updateProperties];
|
|
43
|
+
}
|
|
44
|
+
[self reportRegions];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
- (void)didMoveToWindow {
|
|
48
|
+
[super didMoveToWindow];
|
|
49
|
+
[self setNeedsLayout];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
- (void)updateEventEmitter:(EventEmitter::Shared const &)eventEmitter {
|
|
53
|
+
[super updateEventEmitter:eventEmitter];
|
|
54
|
+
_hasReported = NO;
|
|
55
|
+
[self reportRegions];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
- (std::vector<double>)currentOcclusion {
|
|
59
|
+
std::vector<double> occlusion;
|
|
60
|
+
if (@available(iOS 27.1, *)) {
|
|
61
|
+
if (self.window == nil) {
|
|
62
|
+
return occlusion;
|
|
63
|
+
}
|
|
64
|
+
NSArray<UIViewReservedRegion *> *regions =
|
|
65
|
+
[self reservedRegionsOfKind:[UIViewReservedRegionKind occlusionRegionKind]];
|
|
66
|
+
for (UIViewReservedRegion *region in regions) {
|
|
67
|
+
CGRect frame = [self convertRect:region.frame toView:nil];
|
|
68
|
+
occlusion.push_back(frame.origin.x);
|
|
69
|
+
occlusion.push_back(frame.origin.y);
|
|
70
|
+
occlusion.push_back(frame.size.width);
|
|
71
|
+
occlusion.push_back(frame.size.height);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return occlusion;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
- (void)reportRegions {
|
|
78
|
+
if (!_eventEmitter) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
std::vector<double> occlusion = [self currentOcclusion];
|
|
82
|
+
if (_hasReported && occlusion == _lastOcclusion) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
_hasReported = YES;
|
|
86
|
+
_lastOcclusion = occlusion;
|
|
87
|
+
std::static_pointer_cast<const RNReservedRegionsViewEventEmitter>(_eventEmitter)
|
|
88
|
+
->onRegionsChange(RNReservedRegionsViewEventEmitter::OnRegionsChange{occlusion});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
@end
|
|
92
|
+
|
|
93
|
+
Class<RCTComponentViewProtocol> RNReservedRegionsViewCls(void) {
|
|
94
|
+
return RNReservedRegionsView.class;
|
|
95
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,43 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
"name": "@momo-kits/reserved-regions",
|
|
3
|
+
"version": "0.167.1-duo.4",
|
|
4
|
+
"description": "Reports screen regions reserved by the system (UIView reserved regions, iOS 27.1+), e.g. the iPhone Duo status bar cluster growing for calls or Live Activities.",
|
|
5
|
+
"main": "./src/index.tsx",
|
|
6
|
+
"files": [
|
|
7
|
+
"src",
|
|
8
|
+
"ios",
|
|
9
|
+
"*.podspec",
|
|
10
|
+
"!ios/build",
|
|
11
|
+
"!**/.*"
|
|
12
|
+
],
|
|
13
|
+
"keywords": [
|
|
14
|
+
"react-native",
|
|
15
|
+
"ios",
|
|
16
|
+
"safe-area",
|
|
17
|
+
"reserved-regions"
|
|
18
|
+
],
|
|
19
|
+
"author": "MoMo Team",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"homepage": "https://www.npmjs.com/package/@momo-kits/reserved-regions",
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"registry": "https://registry.npmjs.org/"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"react": "*",
|
|
27
|
+
"react-native": "*"
|
|
28
|
+
},
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=18.0.0"
|
|
31
|
+
},
|
|
32
|
+
"codegenConfig": {
|
|
33
|
+
"name": "ReservedRegionsSpec",
|
|
34
|
+
"type": "components",
|
|
35
|
+
"jsSrcsDir": "src",
|
|
36
|
+
"ios": {
|
|
37
|
+
"componentProvider": {
|
|
38
|
+
"RNReservedRegionsView": "RNReservedRegionsView"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {}
|
|
6
43
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
|
|
2
|
+
import type { ViewProps } from 'react-native';
|
|
3
|
+
import type {
|
|
4
|
+
DirectEventHandler,
|
|
5
|
+
Double,
|
|
6
|
+
} from 'react-native/Libraries/Types/CodegenTypes';
|
|
7
|
+
|
|
8
|
+
export type RegionsChangeEvent = Readonly<{
|
|
9
|
+
// active occlusion regions in window coordinates, flattened as x, y, width, height
|
|
10
|
+
occlusion: Double[];
|
|
11
|
+
}>;
|
|
12
|
+
|
|
13
|
+
export interface NativeProps extends ViewProps {
|
|
14
|
+
onRegionsChange?: DirectEventHandler<RegionsChangeEvent>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default codegenNativeComponent<NativeProps>('RNReservedRegionsView');
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Platform, type ViewProps } from 'react-native';
|
|
3
|
+
import RNReservedRegionsViewNativeComponent from './RNReservedRegionsViewNativeComponent';
|
|
4
|
+
|
|
5
|
+
export type ReservedRegion = {
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
width: number;
|
|
9
|
+
height: number;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const REGION_STRIDE = 4;
|
|
13
|
+
|
|
14
|
+
const toRegions = (flat: ReadonlyArray<number>): ReservedRegion[] => {
|
|
15
|
+
const regions: ReservedRegion[] = [];
|
|
16
|
+
for (let i = 0; i + REGION_STRIDE <= flat.length; i += REGION_STRIDE) {
|
|
17
|
+
regions.push({
|
|
18
|
+
x: flat[i],
|
|
19
|
+
y: flat[i + 1],
|
|
20
|
+
width: flat[i + 2],
|
|
21
|
+
height: flat[i + 3],
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return regions;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export interface ReservedRegionsViewProps extends ViewProps {
|
|
28
|
+
/**
|
|
29
|
+
* active occlusion regions in window coordinates, sent on mount and whenever they
|
|
30
|
+
* change (e.g. the status bar cluster growing for a call); empty before iOS 27.1
|
|
31
|
+
*/
|
|
32
|
+
onRegionsChange?: (regions: ReservedRegion[]) => void;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* invisible probe reporting the system reserved regions; render it once, full window
|
|
37
|
+
*/
|
|
38
|
+
const ReservedRegionsView: React.FC<ReservedRegionsViewProps> = ({
|
|
39
|
+
onRegionsChange,
|
|
40
|
+
...props
|
|
41
|
+
}) => {
|
|
42
|
+
if (Platform.OS !== 'ios') {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
return (
|
|
46
|
+
<RNReservedRegionsViewNativeComponent
|
|
47
|
+
{...props}
|
|
48
|
+
pointerEvents={'none'}
|
|
49
|
+
onRegionsChange={e =>
|
|
50
|
+
onRegionsChange?.(toRegions(e.nativeEvent.occlusion))
|
|
51
|
+
}
|
|
52
|
+
/>
|
|
53
|
+
);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export { ReservedRegionsView };
|
|
57
|
+
export default ReservedRegionsView;
|
package/README.md
DELETED