react-native-ios-translate-sheet 1.0.1 → 1.1.0
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/ios/IOSTranslateSheet-Bridging-Header.h +4 -0
- package/ios/IOSTranslateSheet.swift +16 -16
- package/ios/IOSTranslateSheetProvider.swift +60 -57
- package/ios/IOSTranslateSheetView.h +2 -9
- package/ios/IOSTranslateSheetView.mm +31 -38
- package/ios/IOSTranslateSheetViewManager.mm +22 -4
- package/lib/commonjs/IOSTranslateSheetViewNativeComponent.js.map +1 -1
- package/lib/module/IOSTranslateSheetViewNativeComponent.js.map +1 -1
- package/lib/typescript/IOSTranslateSheetViewNativeComponent.d.ts +5 -5
- package/lib/typescript/IOSTranslateSheetViewNativeComponent.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/IOSTranslateSheetViewNativeComponent.ts +5 -4
|
@@ -2,25 +2,25 @@ import SwiftUI
|
|
|
2
2
|
import Translation
|
|
3
3
|
|
|
4
4
|
class Props: ObservableObject {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
@Published var text: String = ""
|
|
6
|
+
@Published var isPresented: Bool = false
|
|
7
|
+
@Published var onHide: () -> Void = {}
|
|
8
|
+
@Published var opacity: Double = 0.0
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
struct IOSTranslateSheet: View {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
@ObservedObject var props: Props
|
|
13
|
+
|
|
14
|
+
var body: some View {
|
|
15
|
+
if #available(iOS 17.4, *) {
|
|
16
|
+
Color.clear
|
|
17
|
+
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
18
|
+
.translationPresentation(isPresented: $props.isPresented, text: props.text)
|
|
19
|
+
.onChange(of: props.isPresented) { oldValue, newValue in
|
|
20
|
+
if oldValue == true && newValue == false {
|
|
21
|
+
props.onHide()
|
|
22
|
+
}
|
|
22
23
|
}
|
|
23
|
-
|
|
24
|
+
}
|
|
24
25
|
}
|
|
25
|
-
}
|
|
26
26
|
}
|
|
@@ -2,71 +2,74 @@ import UIKit
|
|
|
2
2
|
import React
|
|
3
3
|
import SwiftUI
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
extension UIView {
|
|
6
|
+
func pinEdges(to view: UIView) {
|
|
7
|
+
translatesAutoresizingMaskIntoConstraints = false
|
|
8
|
+
NSLayoutConstraint.activate([
|
|
9
|
+
leadingAnchor.constraint(equalTo: view.leadingAnchor),
|
|
10
|
+
trailingAnchor.constraint(equalTo: view.trailingAnchor),
|
|
11
|
+
topAnchor.constraint(equalTo: view.topAnchor),
|
|
12
|
+
bottomAnchor.constraint(equalTo: view.bottomAnchor)
|
|
13
|
+
])
|
|
12
14
|
}
|
|
13
|
-
|
|
15
|
+
}
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
didSet {
|
|
17
|
-
props.isPresented = isPresented
|
|
18
|
-
hostingController?.view.isHidden = !isPresented
|
|
19
|
-
}
|
|
20
|
-
}
|
|
17
|
+
public typealias RCTBubblingEventBlock = @convention(block) (_ body: [AnyHashable: Any]?) -> Void
|
|
21
18
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
@objc public class IOSTranslateSheetProvider: UIView {
|
|
20
|
+
private var props = Props()
|
|
21
|
+
private var hostingController: UIHostingController<IOSTranslateSheet>?
|
|
22
|
+
|
|
23
|
+
@objc public var text: String = "" {
|
|
24
|
+
didSet {
|
|
25
|
+
props.text = text
|
|
26
|
+
}
|
|
25
27
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
setupView()
|
|
28
|
+
|
|
29
|
+
@objc public var isPresented: Bool = false {
|
|
30
|
+
didSet {
|
|
31
|
+
props.isPresented = isPresented
|
|
32
|
+
hostingController?.view.isHidden = !isPresented
|
|
33
|
+
}
|
|
33
34
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
|
|
36
|
+
@objc public var opacity: Double = 0.0 {
|
|
37
|
+
didSet {
|
|
38
|
+
props.opacity = opacity
|
|
39
|
+
}
|
|
38
40
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
|
|
42
|
+
@objc public var onHide: RCTBubblingEventBlock? {
|
|
43
|
+
didSet {
|
|
44
|
+
props.onHide = { [weak self] in
|
|
45
|
+
self?.onHide?([:])
|
|
46
|
+
}
|
|
47
|
+
}
|
|
43
48
|
}
|
|
44
49
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
)
|
|
50
|
+
public override func layoutSubviews() {
|
|
51
|
+
super.layoutSubviews()
|
|
52
|
+
setupView()
|
|
53
|
+
}
|
|
50
54
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
private func setupView() {
|
|
56
|
+
if self.hostingController != nil {
|
|
57
|
+
return
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
self.hostingController = UIHostingController(
|
|
61
|
+
rootView: IOSTranslateSheet(
|
|
62
|
+
props: props
|
|
63
|
+
)
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
if let hostingController = self.hostingController {
|
|
67
|
+
hostingController.view.isHidden = !isPresented
|
|
68
|
+
hostingController.view.backgroundColor = UIColor(white: 0.0, alpha: opacity)
|
|
69
|
+
|
|
70
|
+
addSubview(hostingController.view)
|
|
71
|
+
hostingController.view.pinEdges(to: self)
|
|
72
|
+
reactAddController(toClosestParent: hostingController)
|
|
73
|
+
}
|
|
59
74
|
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
extension UIView {
|
|
64
|
-
func pinEdges(to other: UIView) {
|
|
65
|
-
NSLayoutConstraint.activate([
|
|
66
|
-
leadingAnchor.constraint(equalTo: other.leadingAnchor),
|
|
67
|
-
trailingAnchor.constraint(equalTo: other.trailingAnchor),
|
|
68
|
-
topAnchor.constraint(equalTo: other.topAnchor),
|
|
69
|
-
bottomAnchor.constraint(equalTo: other.bottomAnchor)
|
|
70
|
-
])
|
|
71
|
-
}
|
|
72
75
|
}
|
|
@@ -1,18 +1,11 @@
|
|
|
1
|
-
#ifdef
|
|
2
|
-
|
|
1
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
3
2
|
#import <React/RCTViewComponentView.h>
|
|
4
3
|
#import <UIKit/UIKit.h>
|
|
5
4
|
|
|
6
|
-
#ifndef IOSTranslateSheetViewNativeComponent_h
|
|
7
|
-
#define IOSTranslateSheetViewNativeComponent_h
|
|
8
|
-
|
|
9
5
|
NS_ASSUME_NONNULL_BEGIN
|
|
10
6
|
|
|
11
7
|
@interface IOSTranslateSheetView : RCTViewComponentView
|
|
12
8
|
@end
|
|
13
9
|
|
|
14
10
|
NS_ASSUME_NONNULL_END
|
|
15
|
-
|
|
16
|
-
#endif /* IOSTranslateSheetViewNativeComponent_h */
|
|
17
|
-
|
|
18
|
-
#endif /* __cplusplus */
|
|
11
|
+
#endif
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
1
2
|
#import "IOSTranslateSheetView.h"
|
|
2
|
-
|
|
3
|
-
#import
|
|
4
|
-
#import "generated/RNIOSTranslateSheetViewSpec/EventEmitters.h"
|
|
5
|
-
#import "generated/RNIOSTranslateSheetViewSpec/Props.h"
|
|
6
|
-
#import "generated/RNIOSTranslateSheetViewSpec/RCTComponentViewHelpers.h"
|
|
7
|
-
|
|
8
|
-
#import "RCTFabricComponentsPlugins.h"
|
|
3
|
+
#import <React/RCTConvert.h>
|
|
4
|
+
#import <React/RCTFabricComponentsPlugins.h>
|
|
9
5
|
|
|
10
6
|
#if __has_include("IOSTranslateSheet/IOSTranslateSheet-Swift.h")
|
|
11
7
|
#import "IOSTranslateSheet/IOSTranslateSheet-Swift.h"
|
|
@@ -13,14 +9,18 @@
|
|
|
13
9
|
#import "IOSTranslateSheet-Swift.h"
|
|
14
10
|
#endif
|
|
15
11
|
|
|
12
|
+
#import "generated/RNIOSTranslateSheetViewSpec/ComponentDescriptors.h"
|
|
13
|
+
#import "generated/RNIOSTranslateSheetViewSpec/EventEmitters.h"
|
|
14
|
+
#import "generated/RNIOSTranslateSheetViewSpec/Props.h"
|
|
15
|
+
#import "generated/RNIOSTranslateSheetViewSpec/RCTComponentViewHelpers.h"
|
|
16
|
+
|
|
16
17
|
using namespace facebook::react;
|
|
17
18
|
|
|
18
19
|
@interface IOSTranslateSheetView () <RCTIOSTranslateSheetViewViewProtocol>
|
|
19
|
-
|
|
20
20
|
@end
|
|
21
21
|
|
|
22
22
|
@implementation IOSTranslateSheetView {
|
|
23
|
-
IOSTranslateSheetProvider *
|
|
23
|
+
IOSTranslateSheetProvider *_view;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
+ (ComponentDescriptorProvider)componentDescriptorProvider
|
|
@@ -30,54 +30,47 @@ using namespace facebook::react;
|
|
|
30
30
|
|
|
31
31
|
- (instancetype)initWithFrame:(CGRect)frame
|
|
32
32
|
{
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (strongSelf) {
|
|
43
|
-
// Emit the onHide event
|
|
44
|
-
if (strongSelf->_eventEmitter) {
|
|
33
|
+
if (self = [super initWithFrame:frame]) {
|
|
34
|
+
static const auto defaultProps = std::make_shared<const IOSTranslateSheetViewProps>();
|
|
35
|
+
_props = defaultProps;
|
|
36
|
+
_view = [[IOSTranslateSheetProvider alloc] init];
|
|
37
|
+
|
|
38
|
+
__weak __typeof__(self) weakSelf = self;
|
|
39
|
+
_view.onHide = ^(NSDictionary *_) {
|
|
40
|
+
__typeof__(self) strongSelf = weakSelf;
|
|
41
|
+
if (strongSelf && strongSelf->_eventEmitter) {
|
|
45
42
|
std::dynamic_pointer_cast<const IOSTranslateSheetViewEventEmitter>(strongSelf->_eventEmitter)
|
|
46
43
|
->onHide({});
|
|
47
44
|
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return self;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
self.contentView = _view;
|
|
48
|
+
}
|
|
49
|
+
return self;
|
|
55
50
|
}
|
|
56
51
|
|
|
57
52
|
- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
|
|
58
53
|
{
|
|
59
|
-
const auto &oldViewProps = *std::static_pointer_cast<IOSTranslateSheetViewProps
|
|
60
|
-
const auto &newViewProps = *std::static_pointer_cast<IOSTranslateSheetViewProps
|
|
54
|
+
const auto &oldViewProps = *std::static_pointer_cast<const IOSTranslateSheetViewProps>(_props);
|
|
55
|
+
const auto &newViewProps = *std::static_pointer_cast<const IOSTranslateSheetViewProps>(props);
|
|
61
56
|
|
|
62
57
|
if (oldViewProps.text != newViewProps.text) {
|
|
63
|
-
|
|
64
|
-
[_view setText:text];
|
|
58
|
+
_view.text = [[NSString alloc] initWithUTF8String:newViewProps.text.c_str()];
|
|
65
59
|
}
|
|
66
|
-
|
|
67
60
|
if (oldViewProps.isPresented != newViewProps.isPresented) {
|
|
68
|
-
|
|
61
|
+
_view.isPresented = newViewProps.isPresented;
|
|
69
62
|
}
|
|
70
|
-
|
|
71
63
|
if (oldViewProps.opacity != newViewProps.opacity) {
|
|
72
|
-
|
|
64
|
+
_view.opacity = newViewProps.opacity;
|
|
73
65
|
}
|
|
74
66
|
|
|
75
67
|
[super updateProps:props oldProps:oldProps];
|
|
76
68
|
}
|
|
77
69
|
|
|
70
|
+
@end
|
|
71
|
+
|
|
78
72
|
Class<RCTComponentViewProtocol> IOSTranslateSheetViewCls(void)
|
|
79
73
|
{
|
|
80
74
|
return IOSTranslateSheetView.class;
|
|
81
75
|
}
|
|
82
|
-
|
|
83
|
-
@end
|
|
76
|
+
#endif
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
#import <React/RCTViewManager.h>
|
|
2
2
|
#import <React/RCTUIManager.h>
|
|
3
|
+
#import <React/RCTComponent.h>
|
|
3
4
|
#import "RCTBridge.h"
|
|
4
5
|
|
|
6
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
7
|
+
#import <React/RCTConvert.h>
|
|
8
|
+
#import <ReactCommon/RCTTurboModule.h>
|
|
9
|
+
#import "RCTFabricComponentsPlugins.h"
|
|
10
|
+
#endif
|
|
11
|
+
|
|
5
12
|
#if __has_include("IOSTranslateSheet/IOSTranslateSheet-Swift.h")
|
|
6
13
|
#import "IOSTranslateSheet/IOSTranslateSheet-Swift.h"
|
|
7
14
|
#else
|
|
@@ -15,11 +22,22 @@
|
|
|
15
22
|
|
|
16
23
|
RCT_EXPORT_MODULE(IOSTranslateSheetView)
|
|
17
24
|
|
|
18
|
-
- (
|
|
25
|
+
- (UIView *)view
|
|
19
26
|
{
|
|
20
|
-
|
|
27
|
+
IOSTranslateSheetProvider *view = [[IOSTranslateSheetProvider alloc] init];
|
|
28
|
+
return view;
|
|
21
29
|
}
|
|
22
30
|
|
|
23
|
-
RCT_EXPORT_VIEW_PROPERTY(
|
|
31
|
+
RCT_EXPORT_VIEW_PROPERTY(text, NSString)
|
|
32
|
+
RCT_EXPORT_VIEW_PROPERTY(isPresented, BOOL)
|
|
33
|
+
RCT_EXPORT_VIEW_PROPERTY(opacity, double)
|
|
34
|
+
RCT_EXPORT_VIEW_PROPERTY(onHide, RCTDirectEventBlock)
|
|
24
35
|
|
|
25
|
-
|
|
36
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
37
|
+
+ (BOOL)requiresMainQueueSetup
|
|
38
|
+
{
|
|
39
|
+
return YES;
|
|
40
|
+
}
|
|
41
|
+
#endif
|
|
42
|
+
|
|
43
|
+
@end
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_codegenNativeComponent","_interopRequireDefault","require","e","__esModule","default","_default","exports","codegenNativeComponent"],"sourceRoot":"../../src","sources":["IOSTranslateSheetViewNativeComponent.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"names":["_codegenNativeComponent","_interopRequireDefault","require","e","__esModule","default","_default","exports","codegenNativeComponent"],"sourceRoot":"../../src","sources":["IOSTranslateSheetViewNativeComponent.ts"],"mappings":";;;;;;AAMA,IAAAA,uBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA6F,SAAAD,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,IAAAG,QAAA,GAAAC,OAAA,CAAAF,OAAA,GAS9E,IAAAG,+BAAsB,EACnC,uBACF,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["codegenNativeComponent"],"sourceRoot":"../../src","sources":["IOSTranslateSheetViewNativeComponent.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"names":["codegenNativeComponent"],"sourceRoot":"../../src","sources":["IOSTranslateSheetViewNativeComponent.ts"],"mappings":";;AAMA,OAAOA,sBAAsB,MAAM,yDAAyD;AAS5F,eAAeA,sBAAsB,CACnC,uBACF,CAAC","ignoreList":[]}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { DirectEventHandler, Float } from "react-native/Libraries/Types/CodegenTypes";
|
|
1
|
+
import type { ViewProps } from "react-native";
|
|
2
|
+
import type { DirectEventHandler, Float, WithDefault } from "react-native/Libraries/Types/CodegenTypes";
|
|
3
3
|
export interface IOSTranslateSheetProps extends ViewProps {
|
|
4
4
|
text: string;
|
|
5
5
|
isPresented: boolean;
|
|
6
|
-
onHide
|
|
7
|
-
opacity?: Float
|
|
6
|
+
onHide?: DirectEventHandler<null>;
|
|
7
|
+
opacity?: WithDefault<Float, 0.0>;
|
|
8
8
|
}
|
|
9
|
-
declare const _default:
|
|
9
|
+
declare const _default: import("react-native/Libraries/Utilities/codegenNativeComponent").NativeComponentType<IOSTranslateSheetProps>;
|
|
10
10
|
export default _default;
|
|
11
11
|
//# sourceMappingURL=IOSTranslateSheetViewNativeComponent.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IOSTranslateSheetViewNativeComponent.d.ts","sourceRoot":"","sources":["../../src/IOSTranslateSheetViewNativeComponent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"IOSTranslateSheetViewNativeComponent.d.ts","sourceRoot":"","sources":["../../src/IOSTranslateSheetViewNativeComponent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EACV,kBAAkB,EAClB,KAAK,EACL,WAAW,EACZ,MAAM,2CAA2C,CAAC;AAGnD,MAAM,WAAW,sBAAuB,SAAQ,SAAS;IACvD,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,OAAO,CAAC;IACrB,MAAM,CAAC,EAAE,kBAAkB,CAAC,IAAI,CAAC,CAAC;IAClC,OAAO,CAAC,EAAE,WAAW,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;CACnC;;AAED,wBAEE"}
|
package/package.json
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ViewProps } from "react-native";
|
|
2
2
|
import type {
|
|
3
3
|
DirectEventHandler,
|
|
4
4
|
Float,
|
|
5
|
+
WithDefault,
|
|
5
6
|
} from "react-native/Libraries/Types/CodegenTypes";
|
|
6
7
|
import codegenNativeComponent from "react-native/Libraries/Utilities/codegenNativeComponent";
|
|
7
8
|
|
|
8
9
|
export interface IOSTranslateSheetProps extends ViewProps {
|
|
9
10
|
text: string;
|
|
10
11
|
isPresented: boolean;
|
|
11
|
-
onHide
|
|
12
|
-
opacity?: Float
|
|
12
|
+
onHide?: DirectEventHandler<null>;
|
|
13
|
+
opacity?: WithDefault<Float, 0.0>;
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
export default codegenNativeComponent<IOSTranslateSheetProps>(
|
|
16
17
|
"IOSTranslateSheetView",
|
|
17
|
-
)
|
|
18
|
+
);
|