Skip to content

Commit

Permalink
feat(ios): add preventScreenshots configuration option (#105)
Browse files Browse the repository at this point in the history
* lowercased cases of switch in getContentModeFromString

* added disableScreenshots option

* renamed disableScreenshots to preventScreenshots

* fixed erroneous substitution

* added missing file

* updated method comment as suggested

---------

Co-authored-by: ksenia <[email protected]>
  • Loading branch information
nomadminded and aveekam authored Aug 12, 2024
1 parent d4bbee0 commit 9276f48
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ These configuration values are available:
| **`enable`** | <code>boolean</code> | Configure whether the plugin should be enabled from startup. Only available for Android and iOS. | <code>true</code> |
| **`imageName`** | <code>string</code> | Configure whether the plugin should display a custom image from assets instead of a default background gray for the privacy screen. Only available for iOS. | <code>""</code> |
| **`contentMode`** | <code>'center' \| 'scaleToFill' \| 'scaleAspectFit' \| 'scaleAspectFill'</code> | Configure the content mode of displayed image. Only available for iOS. | <code>"center"</code> |
| **`preventScreenshots`** | <code>boolean</code> | Configure whether the plugin should disable/enable the possibility of taking screenshots. Only available for iOS. | <code>true</code> |

### Examples

Expand All @@ -64,7 +65,8 @@ In `capacitor.config.json`:
"PrivacyScreen": {
"enable": true,
"imageName": "Splashscreen",
"contentMode": "scaleAspectFit"
"contentMode": "scaleAspectFit",
"preventScreenshots": true
}
}
}
Expand All @@ -83,6 +85,7 @@ const config: CapacitorConfig = {
enable: true,
imageName: "Splashscreen",
contentMode: "scaleAspectFit",
preventScreenshots: true,
},
},
};
Expand Down
5 changes: 4 additions & 1 deletion ios/Plugin/PrivacyScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ import UIKit
}

self.window = window
configurePreventionScreenshot()
let preventScreenshots = config.preventScreenshots ?? true
if preventScreenshots {
configurePreventionScreenshot()
}
}

public func configurePreventionScreenshot() {
Expand Down
1 change: 1 addition & 0 deletions ios/Plugin/PrivacyScreenConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ public struct PrivacyScreenConfig {
var enable = true
var imageName: String? = ""
var contentMode: String? = "center"
var preventScreenshots: Bool? = true
}
1 change: 1 addition & 0 deletions ios/Plugin/PrivacyScreenPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public class PrivacyScreenPlugin: CAPPlugin {
config.enable = getConfig().getBoolean("enable", config.enable)
config.imageName = getConfig().getString("imageName", config.imageName)
config.contentMode = getConfig().getString("contentMode", config.contentMode)
config.preventScreenshots = getConfig().getBoolean("preventScreenshots", true)
return config
}
}
10 changes: 10 additions & 0 deletions src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ declare module '@capacitor/cli' {
| 'scaleToFill'
| 'scaleAspectFit'
| 'scaleAspectFill';
/**
* Configure whether the plugin should prevent screenshots if enabled.
*
* Only available for iOS.
*
* @default true
* @example false
* @since 5.2.0
*/
preventScreenshots?: boolean;
};
}
}
Expand Down

0 comments on commit 9276f48

Please sign in to comment.