Skip to content

Conversation

@robertherber
Copy link
Member

@robertherber robertherber commented Apr 25, 2025

Summary by CodeRabbit

  • New Features
    • Added support for skipping action execution if the whitelist or blocklist remains unchanged, improving efficiency during monitoring activities.
  • Documentation
    • Expanded and clarified the README with detailed usage examples, new sections on permission handling, app selection, time tracking, and shield blocking, as well as troubleshooting tips and updated code snippets.
  • Chores
    • Updated package version to 0.4.30.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 25, 2025

Walkthrough

This update introduces a mechanism to skip executing certain actions if the whitelist or blocklist of selected apps and domains has not changed. It achieves this by adding a comparison function for FamilyActivitySelection objects and extending relevant methods and types to accept a skipIfWhitelistOrBlacklistIsUnchanged flag along with original whitelist and blocklist values. The logic is integrated into the action execution process within the activity monitor extension. Additionally, the documentation was significantly expanded with new examples and clarifications, and the package version was incremented.

Changes

File(s) Change Summary
README.md Expanded documentation with detailed usage examples, new sections on permissions, app selection, time tracking, shield blocking, and troubleshooting. No code changes.
.../Shared.swift Added isEqual function for comparing FamilyActivitySelection objects; updated shouldExecuteAction to accept new parameters and skip actions if whitelist/blocklist unchanged.
.../DeviceActivityMonitorExtension.swift Captures current whitelist/blocklist at action execution start; passes originals and new skip flag to shouldExecuteAction.
.../ReactNativeDeviceActivity.types.ts Added optional skipIfWhitelistOrBlacklistIsUnchanged property to CommonTypeParams type.
.../package.json Incremented package version from 0.4.28 to 0.4.30.
apps/example/ios/Tests/SkipTests.swift Updated tests to add new parameters in calls to shouldExecuteAction and imported FamilyControls module; no logic changes.

Sequence Diagram(s)

sequenceDiagram
    participant MonitorExtension
    participant Action
    participant Shared

    MonitorExtension->>MonitorExtension: getCurrentWhitelist()
    MonitorExtension->>MonitorExtension: getCurrentBlocklist()
    loop For each action
        MonitorExtension->>Action: Extract skipIfWhitelistOrBlacklistIsUnchanged flag
        MonitorExtension->>Shared: shouldExecuteAction(..., skipIfWhitelistOrBlacklistIsUnchanged, originalWhitelist, originalBlocklist)
        alt Whitelist/Blocklist unchanged and skip flag set
            Shared-->>MonitorExtension: Return false (skip action)
        else
            Shared-->>MonitorExtension: Return true (execute action)
        end
    end
Loading

Poem

A rabbit hops through code so neat,
Comparing lists to skip repeat.
If whitelist, blocklist stay the same,
No need to run the action game!
With docs enhanced and types anew,
This version hops ahead for you.
🐇✨


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Apr 25, 2025

Open in StackBlitz

npm i https://pkg.pr.new/kingstinct/react-native-device-activity@57

commit: 060deed

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 9

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1280393 and 5e29ca5.

📒 Files selected for processing (5)
  • README.md (8 hunks)
  • packages/react-native-device-activity/ios/Shared.swift (3 hunks)
  • packages/react-native-device-activity/package.json (1 hunks)
  • packages/react-native-device-activity/src/ReactNativeDeviceActivity.types.ts (1 hunks)
  • packages/react-native-device-activity/targets/ActivityMonitorExtension/DeviceActivityMonitorExtension.swift (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/react-native-device-activity/ios/Shared.swift (1)
packages/react-native-device-activity/src/index.ts (1)
  • symmetricDifference (249-259)
🪛 LanguageTool
README.md

[typographical] ~18-~18: It seems that a comma is missing.
Context: ... Cases ## Handle permissions To block apps you need to request screen time permiss...

(IN_ORDER_TO_VB_COMMA)


[style] ~68-~68: As an alternative to the over-used intensifier ‘quite’, consider replacing this phrase.
Context: .... - The activitySelection tokens can be quite large (especially if you use includeEntireCat...

(EN_WEAK_ADJECTIVE)


[uncategorized] ~118-~118: A comma might be missing here.
Context: ... need different schedules for different days for example) you might need multiple mo...

(AI_EN_LECTOR_MISSING_PUNCTUATION_COMMA)


[uncategorized] ~118-~118: A comma might be missing here.
Context: ...schedules for different days for example) you might need multiple monitors. There...

(AI_EN_LECTOR_MISSING_PUNCTUATION_COMMA)


[typographical] ~122-~122: It seems that a comma is missing.
Context: ...se case. ## Block the shield To block apps you can do it directly from your code. ...

(IN_ORDER_TO_VB_COMMA)


[uncategorized] ~162-~162: Possible missing article found.
Context: ... sending web requests or notifications. Easiest way to explore this is exploring this w...

(AI_HYDRA_LEO_MISSING_THE)


[grammar] ~248-~248: Use “the” before the superlative.
Context: ...f the Shield UI/actions. We try to make a best guess here - prioritizing apps/web...

(THE_SUPERLATIVE)


[uncategorized] ~248-~248: Possible missing comma found.
Context: ...lay a shield specific for the Instagram selection that will take precedence over the less...

(AI_HYDRA_LEO_MISSING_COMMA)

🪛 SwiftLint (0.57.0)
packages/react-native-device-activity/ios/Shared.swift

[Warning] 1269-1269: if, for, guard, switch, while, and catch statements shouldn't unnecessarily wrap their conditionals or arguments in parentheses

(control_statement)


[Warning] 1272-1272: if, for, guard, switch, while, and catch statements shouldn't unnecessarily wrap their conditionals or arguments in parentheses

(control_statement)


[Warning] 1269-1269: Opening braces should be preceded by a single space and on the same line as the declaration

(opening_brace)


[Warning] 1272-1272: Opening braces should be preceded by a single space and on the same line as the declaration

(opening_brace)

🔇 Additional comments (16)
packages/react-native-device-activity/package.json (1)

3-3: Package version increment looks good.

The version number was incremented from 0.4.28 to 0.4.29, following semantic versioning conventions for this minor feature addition.

packages/react-native-device-activity/src/ReactNativeDeviceActivity.types.ts (1)

217-217: Well-placed optional flag for optimization.

Adding the skipIfWhitelistOrBlacklistIsUnchanged flag to CommonTypeParams is a good optimization that allows consumers to avoid unnecessary actions when no changes have occurred to the whitelist or blocklist.

packages/react-native-device-activity/targets/ActivityMonitorExtension/DeviceActivityMonitorExtension.swift (3)

68-69: Good implementation for capturing the original state.

Capturing the original whitelist and blocklist at the beginning of action execution establishes a baseline for comparison, enabling the optimization feature to work properly.


91-91: Well-placed extraction of the flag.

Correctly extracting the skipIfWhitelistOrBlacklistIsUnchanged flag from the action dictionary maintains consistency with the TypeScript type definition.


104-106: Good parameter passing to the shouldExecuteAction function.

Passing the original whitelist, blocklist, and the flag to the shouldExecuteAction function enables the comparison logic to work correctly.

packages/react-native-device-activity/ios/Shared.swift (2)

1236-1242: Good implementation of the equality check function.

The isEqual function efficiently compares two FamilyActivitySelection objects by using the symmetric difference operation and checking if the result is empty. This approach is elegant and maintains consistency with the existing codebase style.


1254-1256: Good parameter addition to the shouldExecuteAction function.

Adding the new parameters to the shouldExecuteAction function signature maintains good code organization and provides all necessary data for the optimization feature.

README.md (9)

14-16: Addition of "Examples & Use Cases" section and permissions header

The new section and subheader clearly organize the documentation for quick discovery.


23-27: Approve code snippet for requesting authorization

The useEffect example correctly demonstrates how to request permissions on mount.


29-33: Approve code snippet for revoking authorization

The revokeAuthorization example is concise and clear.


37-39: Approve DeviceActivitySelectionView usage example

This snippet effectively shows how to render the native selection view and handle callbacks.


74-75: Approve import snippet for time tracking

The import example clearly shows the module usage.


80-80: Approve monitoring activity name example

Using "TimeTrackingActivity" helps illustrate naming conventions.


97-97: Approve event listener example

The listener setup is clearly described and accurately demonstrates usage.


116-117: Approve notes introduction

The “Some things worth noting here:” heading effectively segments additional tips.


136-144: Approve BlockAfter10Minutes monitoring example

The snippet clearly illustrates how to set up an event with blocking actions.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

♻️ Duplicate comments (1)
packages/react-native-device-activity/ios/Shared.swift (1)

1269-1277: Implementation of skip logic looks good.

The code correctly implements the logic for skipping actions when the whitelist and blocklist haven't changed.

The style has been improved according to previous review comments, with proper spacing and removal of unnecessary parentheses.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Lite

📥 Commits

Reviewing files that changed from the base of the PR and between 39af212 and 62b126a.

📒 Files selected for processing (1)
  • packages/react-native-device-activity/ios/Shared.swift (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/react-native-device-activity/ios/Shared.swift (1)
packages/react-native-device-activity/src/index.ts (1)
  • symmetricDifference (249-259)

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Lite

📥 Commits

Reviewing files that changed from the base of the PR and between 62b126a and 3bdc570.

📒 Files selected for processing (1)
  • README.md (8 hunks)
🔇 Additional comments (3)
README.md (3)

14-16: Approve Examples section addition

The new # Examples & Use Cases section and the ## Handle permissions subheading align well with the existing structure and improve discoverability of usage guidance.


35-35: Approve Select Apps section header

The ## Select Apps to track heading clearly introduces the next usage example and follows the existing documentation style.


256-259: 🧹 Nitpick (assertive)

Ensure bullet capitalization consistency

The bullet list mixes lowercase and uppercase starts. Align them by capitalizing the first word of each item, e.g.:

- familyActivitySelectionId mapping. This makes it possible for us to tie a familyActivitySelection token to an id that we can reuse and refer to at a later stage.
+ FamilyActivitySelectionId mapping. This makes it possible for us to tie a familyActivitySelection token to an id that we can reuse and refer to at a later stage.

Likely an incorrect or invalid review comment.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Lite

📥 Commits

Reviewing files that changed from the base of the PR and between 3bdc570 and bb86983.

📒 Files selected for processing (1)
  • README.md (8 hunks)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Lite

📥 Commits

Reviewing files that changed from the base of the PR and between bb86983 and 8de742d.

📒 Files selected for processing (1)
  • packages/react-native-device-activity/package.json (1 hunks)
🔇 Additional comments (2)
packages/react-native-device-activity/package.json (2)

3-3: Version bump looks correct.
The package version has been updated from 0.4.28 to 0.4.30 to reflect the new flag and documentation changes.


3-3: Verify version consistency in native modules.
Please ensure that this version bump is echoed in your iOS Podspec, Android Gradle metadata, and any other build or distribution artifacts (e.g., CocoaPods, Maven Central).

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

♻️ Duplicate comments (4)
README.md (4)

123-123: Clarify programmatic blocking phrasing
Instead of “To block apps, you can do it directly from your code.”, consider:

- To block apps, you can do it directly from your code.
+ To block apps programmatically, call the `blockSelection` method:

257-258: 🧹 Nitpick (assertive)

Wrap code-like identifiers and fix casing
In the Data model bullets, wrap code keys in backticks and correct “userDefaults” to “UserDefaults” for consistency:

- Prefixed like actions*for*${goalId} in userDefaults.
+ Prefixed like `actionsFor${goalId}` in UserDefaults.

- Prefixed like events_${goalId} in userDefaults.
+ Prefixed like `events_${goalId}` in UserDefaults.

153-155: ⚠️ Potential issue

Fix missing property assignment in action example
The actions object is missing a key–value pair for familyActivitySelectionId. It should be something like:

- {
-   type: "blockSelection",
-   familyActivitySelectionId,
- }
+ {
+   type: "blockSelection",
+   familyActivitySelectionId: selectionId,
+ }

119-119: 🧹 Nitpick (assertive)

Add commas around “for example”
In the parenthetical phrase, insert commas around “for example” for readability:

- Depending on your use case (if you need different schedules for different days for example) you might need multiple monitors.
+ Depending on your use case (if you need different schedules for different days, for example), you might need multiple monitors.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Lite

📥 Commits

Reviewing files that changed from the base of the PR and between 8de742d and 060deed.

📒 Files selected for processing (1)
  • README.md (8 hunks)

@robertherber robertherber merged commit 6bc6c6d into main Apr 27, 2025
11 checks passed
@robertherber robertherber deleted the improve-docs branch April 27, 2025 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants