react-native#DeviceEventEmitter JavaScript Examples
The following examples show how to use
react-native#DeviceEventEmitter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: api.js From filen-mobile with GNU Affero General Public License v3.0 | 6 votes |
favoriteItem = ({ item, value }) => {
return new Promise((resolve, reject) => {
apiRequest({
method: "POST",
endpoint: "/v1/item/favorite",
data: {
apiKey: getAPIKey(),
uuid: item.uuid,
type: item.type,
value
}
}).then((response) => {
if(!response.status){
return reject(response.message)
}
DeviceEventEmitter.emit("event", {
type: "mark-item-favorite",
data: {
uuid: item.uuid,
value: value == 1 ? true : false
}
})
updateLoadItemsCache({
item,
prop: "favorited",
value
}).then(() => {
return resolve()
})
}).catch(reject)
})
}
Example #2
Source File: OnboardingWrapper.js From haven with MIT License | 6 votes |
async componentWillMount() {
const { setOnboardingStatus } = this.props;
try {
await getConfig();
this.handleServerStarted();
} catch (err) {
if (Platform.OS === 'ios') {
iOSeventEmitter.addListener('onServerStarted', this.handleServerStarted);
} else {
DeviceEventEmitter.addListener('onServerStarted', this.handleServerStarted);
}
setOnboardingStatus('offline');
}
}
Example #3
Source File: offline.js From filen-mobile with GNU Affero General Public License v3.0 | 6 votes |
removeFromOfflineStorage = ({ item }) => {
return new Promise((resolve, reject) => {
getDownloadPath({ type: "offline" }).then(async (path) => {
path = getItemOfflinePath(path, item)
try{
if((await RNFS.exists(path))){
await RNFS.unlink(path)
}
}
catch(e){
console.log(e)
}
removeItemFromOfflineList({ item }).then(() => {
DeviceEventEmitter.emit("event", {
type: "mark-item-offline",
data: {
uuid: item.uuid,
value: false
}
})
return resolve()
}).catch(reject)
}).catch(reject)
})
}
Example #4
Source File: index.android.js From bluezone-app with GNU General Public License v3.0 | 6 votes |
async componentDidMount() {
// this.checkBluetoothState();
registerBluetoothStateListener(this.setStatusBluetooth);
AppState.addEventListener('change', this.handleAppStateChange);
// TODO both DeviceEventEmitter and NativeAppEventEmitter are deprecated, you should use NativeEventEmitter instead.
DeviceEventEmitter.addListener(
RNSettings.GPS_PROVIDER_EVENT,
this.handleGPSProviderEvent,
);
this.timer = setTimeout(this.requestPermissionLocation, 500);
}
Example #5
Source File: api.js From filen-mobile with GNU Affero General Public License v3.0 | 6 votes |
bulkRemoveSharedIn = ({ items }) => {
return new Promise(async (resolve, reject) => {
for(let i = 0; i < items.length; i++){
const item = items[i]
try{
await removeSharedInItem({ item })
DeviceEventEmitter.emit("event", {
type: "remove-item",
data: {
uuid: item.uuid
}
})
}
catch(e){
console.log(e)
}
}
return resolve()
})
}
Example #6
Source File: DeviceSecurity.js From RRWallet with MIT License | 6 votes |
constructor() {
AppState.addEventListener("change", nextAppState => {
if (nextAppState == "active") {
this.showUnlockIfNeed();
} else {
this.leaveTimestamp = new Date().getTime();
}
});
DeviceEventEmitter.addListener(NOTIFICATION_AUTH_FINISH, () => {
this.isUnlocking = false;
});
}
Example #7
Source File: Worker.js From rn-background-queue-processor with MIT License | 6 votes |
/**
* Constructor for worker
*/
constructor(queue=[]) {
DeviceEventEmitter.addListener(EVENT_START_PROCESSING_QUEUE, this.syncPackagesUpListener.bind(this));
if (Worker.instance) {
return Worker.instance;
}
Worker.instance = this;
this.allQueues = queue;
this.queueProcessor = new QueueProcessor();
return this;
}
Example #8
Source File: SplashPortal.js From RRWallet with MIT License | 6 votes |
componentDidMount() {
setTimeout(() => {
// Splash.dismissIfNeed(4);
DeviceEventEmitter.emit(NOTIFICATION_SPLASH_START, {
splashStatus: this.splashStatus,
});
}, 0);
DeviceSecurity.splashShowing = true;
SplashUtil.splashing = true;
}
Example #9
Source File: items.js From filen-mobile with GNU Affero General Public License v3.0 | 5 votes |
getFolderSizeFromCache = ({ folder, routeURL, load = true }) => {
const cacheKey = getFolderSizeCacheKey({ folder, routeURL })
try{
var cache = storage.getNumber(cacheKey)
if(load){
var timeout = storage.getNumber(cacheKey + ":timeout")
}
}
catch(e){
return 0
}
if(load){
const netInfo = useStore.getState().netInfo
if(Math.floor(+new Date()) > timeout && netInfo.isConnected && netInfo.isInternetReachable){
fetchFolderSize({ folder, routeURL }).then(async (size) => {
try{
if(cache == size){
await storage.setAsync(cacheKey + ":timeout", (Math.floor(+new Date()) + 15000))
return false
}
await storage.setAsync(cacheKey, size)
await storage.setAsync(cacheKey + ":timeout", (Math.floor(+new Date()) + 45000))
}
catch(e){
return console.log(e)
}
updateLoadItemsCache({
item: folder,
prop: "size",
value: size
}).then(() => {
DeviceEventEmitter.emit("event", {
type: "folder-size",
data: {
uuid: folder.uuid,
size
}
})
})
}).catch((err) => {
console.log(err)
})
}
}
return (typeof cache == "number" ? cache : 0)
}
Example #10
Source File: launch.android.js From RRWallet with MIT License | 5 votes |
DeviceEventEmitter.addListener(NOTIFICATION_AUTH_FINISH, () => {
launch(restoreOptions);
});
Example #11
Source File: Item.js From filen-mobile with GNU Affero General Public License v3.0 | 5 votes |
render(){
const { item, index, darkMode } = this.props
const windowWidth = this.props.dimensions.window.width || window.width
const imageWidthAndHeight = Math.floor(windowWidth - 30)
return (
<TouchableOpacity activeOpacity={0.6} key={index.toString()} style={{
height: imageWidthAndHeight,
width: imageWidthAndHeight,
paddingLeft: 30,
alignItems: "center",
justifyContent: "center",
marginBottom: 25
}} onPress={() => this.props.photosRangeItemClick(item)}>
<FastImage source={this.props.hideThumbnails ? getImageForItem(item) : typeof item.thumbnail !== "undefined" ? { uri: "file://" + THUMBNAIL_BASE_PATH + item.thumbnail } : getImageForItem(item)} style={{
width: typeof item.thumbnail !== "undefined" && !this.props.hideThumbnails ? imageWidthAndHeight : 40,
height: typeof item.thumbnail !== "undefined" && !this.props.hideThumbnails ? imageWidthAndHeight : 40,
zIndex: 2,
borderRadius: typeof item.thumbnail !== "undefined" ? 15 : 0
}} onError={() => {
if(typeof item.thumbnail == "string"){
DeviceEventEmitter.emit("event", {
type: "check-thumbnail",
item
})
}
}} />
<View style={{
backgroundColor: darkMode ? "rgba(34, 34, 34, 0.5)" : "rgba(128, 128, 128, 0.6)",
position: "absolute",
zIndex: 100,
top: 15,
left: 30,
zIndex: 100,
padding: 5,
paddingLeft: 10,
paddingRight: 10,
borderRadius: 15
}}>
<Text style={{
color: "white",
fontWeight: "bold",
fontSize: 20
}}>
{item.title}
</Text>
</View>
{
typeof item.remainingItems == "number" && item.remainingItems > 1 && (
<View style={{
backgroundColor: darkMode ? "rgba(34, 34, 34, 0.7)" : "rgba(128, 128, 128, 0.7)",
width: "auto",
height: "auto",
borderRadius: 15,
position: "absolute",
zIndex: 100,
padding: 5,
paddingLeft: 10,
top: 15,
right: 0,
flexDirection: "row"
}} pointerEvents="box-none">
<Text style={{
color: "white",
fontSize: 15
}}>{item.remainingItems}</Text>
<Ionicon name="chevron-forward-outline" size={16} color="white" style={{
marginTop: Platform.OS == "android" ? 2.25 : 0.5,
marginLeft: 2
}} />
</View>
)
}
</TouchableOpacity>
)
}