-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
185 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"platforms": ["ios"], | ||
"ios": { | ||
"modules": ["ExpoBlueskyTranslateModule"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export { | ||
ExpoBlueskyTranslateView, | ||
isAvailable, | ||
} from './src/ExpoBlueskyTranslateView' |
20 changes: 20 additions & 0 deletions
20
modules/expo-bluesky-translate/ios/Common/UIHostingControllerCompat.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import ExpoModulesCore | ||
import SwiftUI | ||
|
||
// Thanks to Andrew Levy for this code snippet | ||
// https://github.com/andrew-levy/swiftui-react-native/blob/d3fbb2abf07601ff0d4b83055e7717bb980910d6/ios/Common/ExpoView%2BUIHostingController.swift | ||
|
||
extension ExpoView { | ||
func setupHostingController(_ hostingController: UIHostingController<some View>) { | ||
hostingController.view.translatesAutoresizingMaskIntoConstraints = false | ||
hostingController.view.backgroundColor = .clear | ||
|
||
addSubview(hostingController.view) | ||
NSLayoutConstraint.activate([ | ||
hostingController.view.topAnchor.constraint(equalTo: self.topAnchor), | ||
hostingController.view.bottomAnchor.constraint(equalTo: self.bottomAnchor), | ||
hostingController.view.leftAnchor.constraint(equalTo: self.leftAnchor), | ||
hostingController.view.rightAnchor.constraint(equalTo: self.rightAnchor), | ||
]) | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
modules/expo-bluesky-translate/ios/ExpoBlueskyTranslate.podspec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Pod::Spec.new do |s| | ||
s.name = 'ExpoBlueskyTranslate' | ||
s.version = '1.0.0' | ||
s.summary = 'Uses SwiftUI translation to translate text.' | ||
s.description = 'Uses SwiftUI translation to translate text.' | ||
s.author = '' | ||
s.homepage = 'https://docs.expo.dev/modules/' | ||
s.platforms = { :ios => '13.4' } | ||
s.source = { git: '' } | ||
s.static_framework = true | ||
|
||
s.dependency 'ExpoModulesCore' | ||
|
||
# Swift/Objective-C compatibility | ||
s.pod_target_xcconfig = { | ||
'DEFINES_MODULE' => 'YES', | ||
'SWIFT_COMPILATION_MODE' => 'wholemodule' | ||
} | ||
|
||
s.source_files = "**/*.{h,m,mm,swift,hpp,cpp}" | ||
end |
18 changes: 18 additions & 0 deletions
18
modules/expo-bluesky-translate/ios/ExpoBlueskyTranslateModule.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import ExpoModulesCore | ||
import Foundation | ||
import SwiftUI | ||
|
||
public class ExpoBlueskyTranslateModule: Module { | ||
public func definition() -> ModuleDefinition { | ||
Name("ExpoBlueskyTranslate") | ||
View(ExpoBlueskyTranslateView.self) { | ||
Events("onEvent") | ||
Prop("text") { (view: ExpoBlueskyTranslateView, text: String) in | ||
view.props.text = text | ||
} | ||
Prop("isPresented") { (view: ExpoBlueskyTranslateView, isPresented: Bool) in | ||
view.props.isPresented = isPresented | ||
} | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
modules/expo-bluesky-translate/ios/ExpoBlueskyTranslateView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import ExpoModulesCore | ||
import Foundation | ||
import SwiftUI | ||
|
||
class TranslateViewProps: ObservableObject { | ||
@Published var text: String = "" | ||
@Published var isPresented: Bool = false | ||
@Published var children: [UIView]? | ||
@Published var onEvent: EventDispatcher | ||
init(onEvent: EventDispatcher) { | ||
self.onEvent = onEvent | ||
} | ||
} | ||
|
||
class ExpoBlueskyTranslateView: ExpoView { | ||
let props: TranslateViewProps | ||
let onEvent = EventDispatcher() | ||
|
||
override func didUpdateReactSubviews() { | ||
let subChildren = self.reactSubviews() | ||
props.children = subChildren | ||
} | ||
|
||
required init(appContext: AppContext? = nil) { | ||
props = TranslateViewProps(onEvent: onEvent) | ||
let hostingController = UIHostingController(rootView: TranslateView(props: props)) | ||
super.init(appContext: appContext) | ||
setupHostingController(hostingController) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import SwiftUI | ||
import Translation | ||
|
||
struct TranslateView: View { | ||
@ObservedObject var props: TranslateViewProps | ||
|
||
var body: some View { | ||
if #available(iOS 17.4, *) { | ||
VStack { | ||
ForEach(props.children?.indices ?? 0..<0, id: \.self) { index in | ||
UIViewRepresentableWrapper(view: props.children?[index] ?? UIView()) | ||
.frame( | ||
width: props.children?[index].frame.width, | ||
height: props.children?[index].frame.height) | ||
} | ||
} | ||
.translationPresentation( | ||
isPresented: $props.isPresented, | ||
text: props.text | ||
) | ||
} | ||
} | ||
} | ||
|
||
struct UIViewRepresentableWrapper: UIViewRepresentable { | ||
let view: UIView | ||
|
||
func makeUIView(context: Context) -> UIView { | ||
return view | ||
} | ||
|
||
func updateUIView(_ uiView: UIView, context: Context) {} | ||
} |
7 changes: 7 additions & 0 deletions
7
modules/expo-bluesky-translate/src/ExpoBlueskyTranslate.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import React from 'react' | ||
|
||
export type ExpoBlueskyTranslateProps = { | ||
text: string | ||
isPresented?: boolean | ||
children: React.ReactNode | ||
} |
14 changes: 14 additions & 0 deletions
14
modules/expo-bluesky-translate/src/ExpoBlueskyTranslateView.ios.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import React from 'react' | ||
import {Platform} from 'react-native' | ||
import {requireNativeViewManager} from 'expo-modules-core' | ||
|
||
import {ExpoBlueskyTranslateProps} from './ExpoBlueskyTranslate.types' | ||
|
||
const NativeView: React.ComponentType<ExpoBlueskyTranslateProps> = | ||
requireNativeViewManager('ExpoBlueskyTranslate') | ||
|
||
export function ExpoBlueskyTranslateView(props: ExpoBlueskyTranslateProps) { | ||
return <NativeView {...props} /> | ||
} | ||
|
||
export const isAvailable = Number(Platform.Version) >= 17.4 |
7 changes: 7 additions & 0 deletions
7
modules/expo-bluesky-translate/src/ExpoBlueskyTranslateView.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import {ExpoBlueskyTranslateProps} from './ExpoBlueskyTranslate.types' | ||
|
||
export function ExpoBlueskyTranslateView(_: ExpoBlueskyTranslateProps) { | ||
return null | ||
} | ||
|
||
export const isAvailable = false |
2 changes: 2 additions & 0 deletions
2
modules/expo-scroll-forwarder/src/ExpoScrollForwarderView.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters