-
Notifications
You must be signed in to change notification settings - Fork 69
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
11 changed files
with
209 additions
and
66 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 |
---|---|---|
@@ -1,5 +1,2 @@ | ||
|
||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="io.csie.kudo.reactnative.v8"> | ||
|
||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
</manifest> |
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
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 |
---|---|---|
@@ -1,3 +1,2 @@ | ||
<manifest package="io.csie.kudo.reactnative.v8.expo" xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
</manifest> |
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,45 @@ | ||
/* | ||
* Copyright (c) Kudo Chien. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#include "MainLoopRegistry.h" | ||
|
||
namespace rnv8 { | ||
|
||
// static | ||
MainLoopRegistry *MainLoopRegistry::GetInstance() { | ||
static MainLoopRegistry instance; | ||
return &instance; | ||
} | ||
|
||
void MainLoopRegistry::RegisterCallback(Callback callback) { | ||
std::lock_guard<std::mutex> lock(mutex_); | ||
callbacks_.push_back(std::move(callback)); | ||
} | ||
|
||
void MainLoopRegistry::UnregisterCallback(const Callback &callback) { | ||
std::lock_guard<std::mutex> lock(mutex_); | ||
callbacks_.erase( | ||
std::remove_if( | ||
callbacks_.begin(), | ||
callbacks_.end(), | ||
[&callback](const Callback ®istered_callback) { | ||
return callback.target_type() == | ||
registered_callback.target_type() && | ||
callback.target<void()>() == | ||
registered_callback.target<void()>(); | ||
}), | ||
callbacks_.end()); | ||
} | ||
|
||
void MainLoopRegistry::OnMainLoopIdle() { | ||
std::lock_guard<std::mutex> lock(mutex_); | ||
for (const auto &callback : callbacks_) { | ||
callback(); | ||
} | ||
} | ||
|
||
} // namespace rnv8 |
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,41 @@ | ||
/* | ||
* Copyright (c) Kudo Chien. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <algorithm> | ||
#include <functional> | ||
#include <mutex> | ||
#include <vector> | ||
|
||
namespace rnv8 { | ||
|
||
class MainLoopRegistry { | ||
public: | ||
using Callback = std::function<void()>; | ||
|
||
static MainLoopRegistry *GetInstance(); | ||
|
||
public: | ||
void RegisterCallback(Callback callback); | ||
|
||
void UnregisterCallback(const Callback &callback); | ||
|
||
void OnMainLoopIdle(); | ||
|
||
private: | ||
MainLoopRegistry() = default; | ||
~MainLoopRegistry() = default; | ||
|
||
MainLoopRegistry(const MainLoopRegistry &) = delete; | ||
MainLoopRegistry &operator=(const MainLoopRegistry &) = delete; | ||
|
||
std::vector<Callback> callbacks_; | ||
std::mutex mutex_; | ||
}; | ||
|
||
} // namespace rnv8 |
Oops, something went wrong.