Skip to content

Commit

Permalink
feat: iOS background prevent (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
wn-na authored Jul 2, 2024
2 parents b6b211d + a0888ee commit e47066a
Show file tree
Hide file tree
Showing 10 changed files with 219 additions and 88 deletions.
48 changes: 24 additions & 24 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
name: Setup
description: Setup Node.js and install dependencies
# name: Setup
# description: Setup Node.js and install dependencies

runs:
using: composite
steps:
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version-file: .nvmrc
# runs:
# using: composite
# steps:
# - name: Setup Node.js
# uses: actions/setup-node@v3
# with:
# node-version-file: .nvmrc

- name: Cache dependencies
id: yarn-cache
uses: actions/cache@v3
with:
path: |
**/node_modules
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
# - name: Cache dependencies
# id: yarn-cache
# uses: actions/cache@v3
# with:
# path: |
# **/node_modules
# key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
# restore-keys: |
# ${{ runner.os }}-yarn-

- name: Install dependencies
if: steps.yarn-cache.outputs.cache-hit != 'true'
run: |
yarn install --cwd example --frozen-lockfile
yarn install --frozen-lockfile
shell: bash
# - name: Install dependencies
# if: steps.yarn-cache.outputs.cache-hit != 'true'
# run: |
# yarn install --cwd example --frozen-lockfile
# yarn install --frozen-lockfile
# shell: bash
96 changes: 48 additions & 48 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
name: CI
on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup
uses: ./.github/actions/setup

- name: Lint files
run: yarn lint

# - name: Typecheck files
# run: yarn typecheck

# test:
# runs-on: ubuntu-latest
# steps:
# - name: Checkout
# uses: actions/checkout@v3

# - name: Setup
# uses: ./.github/actions/setup

# - name: Run unit tests
# run: yarn test --maxWorkers=2 --coverage

# build:
# runs-on: ubuntu-latest
# steps:
# - name: Checkout
# uses: actions/checkout@v3

# - name: Setup
# uses: ./.github/actions/setup

# - name: Build package
# run: yarn prepack
# name: CI
# on:
# push:
# branches:
# - main
# pull_request:
# branches:
# - main

# jobs:
# lint:
# runs-on: ubuntu-latest
# steps:
# - name: Checkout
# uses: actions/checkout@v3

# - name: Setup
# uses: ./.github/actions/setup

# - name: Lint files
# run: yarn lint

# # - name: Typecheck files
# # run: yarn typecheck

# # test:
# # runs-on: ubuntu-latest
# # steps:
# # - name: Checkout
# # uses: actions/checkout@v3

# # - name: Setup
# # uses: ./.github/actions/setup

# # - name: Run unit tests
# # run: yarn test --maxWorkers=2 --coverage

# # build:
# # runs-on: ubuntu-latest
# # steps:
# # - name: Checkout
# # uses: actions/checkout@v3

# # - name: Setup
# # uses: ./.github/actions/setup

# # - name: Build package
# # run: yarn prepack
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
![Simulator Screen Recording](https://user-images.githubusercontent.com/37437842/206644553-e4c3f2bc-b624-47ac-a005-132199e049b2.gif)

![Simulator Screen Recording - iPhone 15 Pro - 2024-07-02 at 21 19 17](https://github.com/0xlethe/react-native-capture-protection/assets/37437842/ac98e942-8dba-4e5d-9f23-fa10f946b26b)

## Features

- iOS Capture Event via screen recording, capture capture with Listener
Expand Down
28 changes: 20 additions & 8 deletions example/0.73/src/Main.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as React from 'react';
import { StyleSheet, View, Button, Text } from 'react-native';
import {StyleSheet, View, Button, Text} from 'react-native';
import {
CaptureProtection,
CaptureProtectionModuleStatus,
useCaptureProtection,
} from 'react-native-capture-protection';
import { useNavigation } from '@react-navigation/native';
import {useNavigation} from '@react-navigation/native';
export default function Main() {
const { isPrevent, status } = useCaptureProtection();
const {isPrevent, status} = useCaptureProtection();
const navigation = useNavigation<any>();

React.useEffect(() => {
Expand All @@ -16,27 +16,27 @@ export default function Main() {
React.useEffect(() => {
console.log(
'Main Prevent Status is',
status ? CaptureProtectionModuleStatus?.[status] : undefined
status ? CaptureProtectionModuleStatus?.[status] : undefined,
);
}, [status]);

return (
<View style={styles.container}>
<Text style={{ color: isPrevent?.record ? 'blue' : 'black' }}>
<Text style={{color: isPrevent?.record ? 'blue' : 'black'}}>
{'Record Prevent : ' + isPrevent?.record}
</Text>
<Text style={{ color: isPrevent?.screenshot ? 'blue' : 'black' }}>
<Text style={{color: isPrevent?.screenshot ? 'blue' : 'black'}}>
{'Screenshot Prevent : ' + isPrevent?.screenshot}
</Text>
<Text style={{ color: 'black' }}>
<Text style={{color: 'black'}}>
{'Status : ' +
(status ? CaptureProtectionModuleStatus?.[status] : undefined)}
</Text>
<Button
title="set Record Protect Screen by Text"
onPress={() => {
CaptureProtection.setScreenRecordScreenWithText?.(
'This is Text Message!'
'This is Text Message!',
);
}}
/>
Expand Down Expand Up @@ -70,6 +70,18 @@ export default function Main() {
CaptureProtection.preventScreenshot();
}}
/>
<Button
title="allow background"
onPress={() => {
CaptureProtection.allowBackground();
}}
/>
<Button
title="prevent background"
onPress={() => {
CaptureProtection.preventBackground();
}}
/>
</View>
);
}
Expand Down
13 changes: 13 additions & 0 deletions example/under0.73/src/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ export default function Main() {
CaptureProtection.preventScreenshot();
}}
/>

<Button
title="allow background"
onPress={() => {
CaptureProtection.allowBackground();
}}
/>
<Button
title="prevent background"
onPress={() => {
CaptureProtection.preventBackground();
}}
/>
</View>
);
}
Expand Down
Loading

0 comments on commit e47066a

Please sign in to comment.