-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
4. Call Swift/Kotlin from TurboModule
- Loading branch information
Showing
6 changed files
with
98 additions
and
9 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
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,25 @@ | ||
// | ||
// PlatformAdapter.h | ||
// my-turbo-utils | ||
// | ||
// Created by Bartłomiej Klocek on 19/05/2021. | ||
// | ||
|
||
#ifndef PlatformAdapter_h | ||
#define PlatformAdapter_h | ||
|
||
#include <string> | ||
|
||
namespace turboutils { | ||
|
||
|
||
class PlatformAdapter { | ||
public: | ||
virtual ~PlatformAdapter() = default; | ||
|
||
virtual std::string delegateGreeting(const std::string &name) = 0; | ||
}; | ||
|
||
} | ||
|
||
#endif /* PlatformAdapter_h */ |
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
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,36 @@ | ||
// | ||
// IosTurboUtilsAdapter.h | ||
// my-turbo-utils | ||
// | ||
// Created by Bartłomiej Klocek on 19/05/2021. | ||
// | ||
|
||
#ifndef IosTurboUtilsAdapter_h | ||
#define IosTurboUtilsAdapter_h | ||
|
||
#include "PlatformAdapter.h" | ||
#import "my_turbo_utils-Swift.h" | ||
|
||
class IosAdapter : public turboutils::PlatformAdapter { | ||
GreetingManager* _greetingManager; | ||
public: | ||
IosAdapter() { | ||
_greetingManager = [[GreetingManager alloc] initWithTag:@"iOS"]; | ||
} | ||
virtual ~IosAdapter() { | ||
_greetingManager = nil; | ||
} | ||
|
||
std::string delegateGreeting(const std::string &name) override { | ||
// convert std::string to NSString* | ||
NSString* nsName = [[NSString alloc] initWithCString:name.c_str() encoding:NSUTF8StringEncoding]; | ||
|
||
// call Swift method | ||
NSString* result = [_greetingManager makeGreetingForName:nsName]; | ||
|
||
// convert back to std::string | ||
return std::string([result UTF8String]); | ||
} | ||
}; | ||
|
||
#endif /* IosTurboUtilsAdapter_h */ |
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