Skip to content

Commit

Permalink
Widget Education (#1040)
Browse files Browse the repository at this point in the history
* Introduce AddWidgetView screen

* Add new copy

* Add Home Message Cell to the Home screen

* Rename AddWidget to WidgetEducation

* Fix theme issue affecting navigation bars and other system components when it is manually overriden in the app

updateUserInterfaceStyle method was being called in willEnterForeground which is not called after cold start

* Remove unused copies

* Open WidgetEducation in modal with navigation bar

* Add pixels

* Make HomeMessageView compliant with iOS 14

* Remove unused code and empty lines

* Remove unsued code around the old home message

* Remove todos, empty lines and warnings

* Turn literal into const

* Add widget education as variant to the manager

* Drop the suffix for WidgetEducationHomeMessageViewModel

* Pass the VariantManager to the Storage and change the logic when to display widgetEducation

* Fix issue for image not showing on WidgetEducationView

* Fix issue with image alignment

* Do not show WidgetEducation feature in settings if it shouldn't be shown

* Do not show widget education if app has been open from widget

* Design adjustments

* Import translations

* Fix tests

* Use lets instead of vars

* Stop allocating weight for voice search

* Make the action closure the last thing so it can benefit from closure style when constructing

Co-authored-by: Jacek Łyp <jlyp@duckduckgo.com>
  • Loading branch information
jaceklyp and jaceklyp committed Feb 11, 2022
1 parent 2488338 commit f5a3a4f
Show file tree
Hide file tree
Showing 98 changed files with 1,999 additions and 900 deletions.
7 changes: 4 additions & 3 deletions Core/Pixel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,6 @@ public enum PixelName: String {
case widgetNewSearch = "m_w_ns"

case defaultBrowserButtonPressedSettings = "m_db_s"
case defaultBrowserButtonPressedHome = "m_db_h"
case defaultBrowserHomeMessageShown = "m_db_h_s"
case defaultBrowserHomeMessageDismissed = "m_db_h_d"

case widgetsOnboardingCTAPressed = "m_o_w_a"
case widgetsOnboardingDeclineOptionPressed = "m_o_w_d"
Expand Down Expand Up @@ -171,6 +168,10 @@ public enum PixelName: String {
case textSizeSettingsShown = "m_text_size_settings_shown"
case textSizeSettingsChanged = "m_text_size_settings_changed"

case widgetEducationOpenedFromHomeScreen = "m_widget_education_opened_from_home"
case widgetEducationOpenedFromSettings = "m_widget_education_opened_from_settings"
case widgetEducationDismissed = "m_widget_education_dismissed"

case jsAlertShown = "m_js_alert_shown"
case jsAlertBlocked = "m_js_alert_blocked"

Expand Down
2 changes: 1 addition & 1 deletion Core/UserDefaultsPropertyWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public struct UserDefaultsWrapper<T> {

case legacyCovidInfo = "com.duckduckgo.ios.home.covidInfo"

case homeDefaultBrowserMessageDateDismissed = "com.duckduckgo.ios.homeMessage.defaultBrowser.dateDismissed"
case homeWidgetEducationMessageDismissed = "com.duckduckgo.ios.homeMessage.widgetEducation.dismissed"

case lastConfigurationRefreshDate = "com.duckduckgo.ios.lastConfigurationRefreshDate"

Expand Down
22 changes: 16 additions & 6 deletions Core/VariantManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public enum FeatureName: String {
// Used for unit tests
case dummy
case voiceSearch
case widgetEducation
case parameterStripping
}

Expand All @@ -44,16 +45,22 @@ public struct Variant {
static let iOS15 = { () -> Bool in
if #available(iOS 15, *) {
return true
} else {
return false
}
return false
}

static let supportsOnDeviceRecognizer = { SFSpeechRecognizer()?.supportsOnDeviceRecognition ?? false }

static let isIOS15EnglishWithOnDeviceSpeech = {
return inEnglish() && iOS15() && supportsOnDeviceRecognizer()
}

static let supportsWidgets = { () -> Bool in
if #available(iOS 14, *) {
return true
}
return false
}
}

static let doNotAllocate = 0
Expand All @@ -66,11 +73,14 @@ public struct Variant {
Variant(name: "sd", weight: doNotAllocate, isIncluded: When.always, features: []),
Variant(name: "se", weight: doNotAllocate, isIncluded: When.always, features: []),

Variant(name: "ma", weight: 1, isIncluded: When.isIOS15EnglishWithOnDeviceSpeech, features: [.voiceSearch]),
Variant(name: "mb", weight: 1, isIncluded: When.isIOS15EnglishWithOnDeviceSpeech, features: []),
Variant(name: "ma", weight: doNotAllocate, isIncluded: When.isIOS15EnglishWithOnDeviceSpeech, features: [.voiceSearch]),
Variant(name: "mb", weight: doNotAllocate, isIncluded: When.isIOS15EnglishWithOnDeviceSpeech, features: []),

Variant(name: "mc", weight: 1, isIncluded: When.always, features: [.parameterStripping]),
Variant(name: "md", weight: 1, isIncluded: When.always, features: [])
Variant(name: "md", weight: 1, isIncluded: When.always, features: []),

Variant(name: "me", weight: 1, isIncluded: When.supportsWidgets, features: [.widgetEducation]),
Variant(name: "mf", weight: 1, isIncluded: When.supportsWidgets, features: [])
]

public let name: String
Expand Down
68 changes: 52 additions & 16 deletions DuckDuckGo.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions DuckDuckGo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

// swiftlint:disable function_body_length
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

#if targetEnvironment(simulator)
if ProcessInfo.processInfo.environment["UITESTING"] == "true" {
// Disable hardware keyboards.
Expand Down Expand Up @@ -123,6 +124,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
UNUserNotificationCenter.current().delegate = self

window?.windowScene?.screenshotService?.delegate = self
ThemeManager.shared.updateUserInterfaceStyle(window: window)

appIsLaunching = true
return true
Expand Down Expand Up @@ -273,12 +275,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
mainViewController?.newTab(reuseExisting: true)
if url.getParam(name: "w") != nil {
Pixel.fire(pixel: .widgetNewSearch)
HomePageConfiguration().dismissHomeMessage(.widgetEducation)
mainViewController?.enterSearch()
}
} else if AppDeepLinks.isLaunchFavorite(url: url) {
let query = AppDeepLinks.query(fromLaunchFavorite: url)
mainViewController?.loadQueryInNewTab(query, reuseExisting: true)
Pixel.fire(pixel: .widgetFavoriteLaunch)
HomePageConfiguration().dismissHomeMessage(.widgetEducation)
} else if AppDeepLinks.isQuickLink(url: url) {
let query = AppDeepLinks.query(fromQuickLink: url)
mainViewController?.loadQueryInNewTab(query, reuseExisting: true)
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/AppDependencyProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class AppDependencyProvider: DependencyProvider {

let appSettings: AppSettings = AppUserDefaults()
let variantManager: VariantManager = DefaultVariantManager()
let homePageConfiguration: HomePageConfiguration = HomePageConfiguration()
lazy var homePageConfiguration: HomePageConfiguration = HomePageConfiguration(variantManager: variantManager)
let storageCache = StorageCacheProvider()
lazy var voiceSearchHelper: VoiceSearchHelperProtocol = VoiceSearchHelper(variantManager)
}
14 changes: 9 additions & 5 deletions DuckDuckGo/Base.lproj/Home.storyboard
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="16097.2" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="19529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_5" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19519"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<customFonts key="customFonts">
Expand Down Expand Up @@ -65,7 +66,7 @@
</imageView>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="TextDuckDuckGo" translatesAutoresizingMaskIntoConstraints="NO" id="0q0-nN-Ola">
<rect key="frame" x="0.0" y="108" width="162" height="21"/>
<color key="tintColor" systemColor="systemBlueColor" red="0.0" green="0.47843137250000001" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="tintColor" systemColor="systemBlueColor"/>
</imageView>
</subviews>
<variation key="heightClass=compact" axis="horizontal"/>
Expand Down Expand Up @@ -118,6 +119,7 @@
</view>
</subviews>
</view>
<viewLayoutGuide key="safeArea" id="3i0-li-iSv"/>
<gestureRecognizers/>
<constraints>
<constraint firstItem="7Jf-KE-oXj" firstAttribute="leading" secondItem="3i0-li-iSv" secondAttribute="leading" id="2Ia-p2-6HX"/>
Expand All @@ -126,7 +128,6 @@
<constraint firstItem="3i0-li-iSv" firstAttribute="trailing" secondItem="7Jf-KE-oXj" secondAttribute="trailing" id="niW-Cm-waP"/>
<constraint firstItem="7Jf-KE-oXj" firstAttribute="top" secondItem="eQ8-iA-i1e" secondAttribute="bottom" constant="32" id="pw7-Bg-mC2"/>
</constraints>
<viewLayoutGuide key="safeArea" id="3i0-li-iSv"/>
<size key="customSize" width="342" height="287"/>
<connections>
<outlet property="imageView" destination="39W-ag-iVs" id="ob1-89-hb0"/>
Expand Down Expand Up @@ -181,6 +182,7 @@
</connections>
</containerView>
</subviews>
<viewLayoutGuide key="safeArea" id="ijV-Vn-w9w"/>
<color key="tintColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstItem="3ms-eB-DjL" firstAttribute="width" secondItem="klK-ZJ-wmA" secondAttribute="width" priority="750" id="12Q-iD-RrD"/>
Expand All @@ -198,7 +200,6 @@
<constraint firstItem="ijV-Vn-w9w" firstAttribute="bottom" secondItem="5Rf-oV-2W5" secondAttribute="bottom" id="iP8-nF-jOV"/>
<constraint firstItem="H74-G9-0WZ" firstAttribute="centerY" secondItem="ijV-Vn-w9w" secondAttribute="centerY" id="vdx-nG-nrB"/>
</constraints>
<viewLayoutGuide key="safeArea" id="ijV-Vn-w9w"/>
<variation key="heightClass=compact">
<mask key="constraints">
<include reference="BjB-Gh-zsj"/>
Expand Down Expand Up @@ -239,5 +240,8 @@
<image name="Settings" width="24" height="24"/>
<image name="SuggestLoupe" width="24" height="24"/>
<image name="TextDuckDuckGo" width="162" height="21"/>
<systemColor name="systemBlueColor">
<color red="0.0" green="0.47843137254901963" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
</resources>
</document>
Loading

0 comments on commit f5a3a4f

Please sign in to comment.