Skip to content

Commit

Permalink
Add doesSelectionHaveOverlap
Browse files Browse the repository at this point in the history
  • Loading branch information
robertherber committed Nov 7, 2024
1 parent d5fbf8d commit a89c799
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
45 changes: 45 additions & 0 deletions ios/ReactNativeDeviceActivityModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,51 @@ public class ReactNativeDeviceActivityModule: Module {
return filteredDict
}

Function("doesSelectionHaveOverlap") { (familyActivitySelections: [String]) in
let decodedFamilyActivitySelections: [FamilyActivitySelection] = familyActivitySelections.map { familyActivitySelection in
let decoder = JSONDecoder()
let data = Data(base64Encoded: familyActivitySelection)
do {
let activitySelection = try decoder.decode(FamilyActivitySelection.self, from: data!)
return activitySelection
}
catch {
return FamilyActivitySelection()
}
}

let hasOverlap = decodedFamilyActivitySelections.contains { selection in
return decodedFamilyActivitySelections.contains { compareWith in
// if it's the same instance - skip comparison
if(compareWith == selection){
return false
}

if(compareWith.applicationTokens.contains(where: { token in
return selection.applicationTokens.contains(token)
} )){
return true
}

if(compareWith.categoryTokens.contains(where: { token in
return selection.categoryTokens.contains(token)
} )){
return true
}

if(compareWith.webDomainTokens.contains(where: { token in
return selection.webDomainTokens.contains(token)
} )){
return true
}

return false
}
}

return hasOverlap
}

Function("authorizationStatus") {
let currentStatus = AuthorizationCenter.shared.authorizationStatus

Expand Down
3 changes: 3 additions & 0 deletions src/ReactNativeDeviceActivity.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ export type ReactNativeDeviceActivityNativeModule = {
revokeAuthorization: () => PromiseLike<void> | void;
blockAllApps: () => PromiseLike<void> | void;
unblockApps: () => PromiseLike<void> | void;
doesSelectionHaveOverlap: (
familyActivitySelections: FamilyActivitySelection[],
) => boolean;
updateShieldConfiguration: (
shieldConfiguration: ShieldConfiguration,
) => PromiseLike<void> | void;
Expand Down
6 changes: 6 additions & 0 deletions src/ReactNativeDeviceActivityModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@ const warnFnNumber = () => {
return 0;
};

const warnFnBoolean = () => {
console.warn(warnText);
return false;
};

const mockModule: ReactNativeDeviceActivityNativeModule & ProxyNativeModule = {
isAvailable: () => false,
requestAuthorization: warnFn,
revokeAuthorization: warnFn,
doesSelectionHaveOverlap: warnFnBoolean,
updateShieldConfiguration: warnFn,
unblockApps: warnFn,
blockAllApps: warnFn,
Expand Down

0 comments on commit a89c799

Please sign in to comment.